Circular reference in a query items request

3859
10
10-28-2015 12:57 AM
Iratxe_Orbe
New Contributor

I am working on a custom widget. One of the things I need to do is to query a group item from AGOL. To do this I use the query items methods as below with the required parameters.

When I work authenticated with an enterprise login, it all worked as it was expected. But when I authenticated with an AGOL user I receive an error: Uncaught RangeError: Maximum call stack size exceeded. It was that when the request that is shown above was done, ArcGIS javascript API was generating an object with a circular reference and the widget crashes. The request is a search (sharing/rest/search) request and the parameters are

the following: f=json&q=group%3A"6264b2c574414393886a3bcb43dd8fba"&sortField=modified&sortOrder=DESC&num=100&token=<token>

If we look at the network tab of the developers tools, the response to this request is correct. So, that this response suffers some changes before arriving to the callback function. Once inside the callback function the data parameter has been modified. Inside each result has a portal object, that contains a user object inside, that references the previous portal oblect again and so on.

This only happens when you are logged in with an AGOL user. It might also be worth mentioning that in our case all AGOL items are inside an enterprise site.

Has this happen to any of you? Have you any solution besides deleting the circular reference objects?

Thanks in advance

0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus

Iratxe,

   Can you share the code you are using to access the AGOL items? When you say

It might also be worth mentioning that in our case all AGOL items are inside an enterprise site.

do you mean a on premise Portal instance?

0 Kudos
Iratxe_Orbe
New Contributor

Hi Robert,

No it is not a Portal instance, it is an AGOL site: http://eea.maps.arcgis.com/

The code is the one above, we are only querying the site.

     this ---> is the widget object

     portal -->

                    

     params -->

                  

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Iratxe,

   Sorry I don't see any actual code in your previous post. Your latest post is also missing the image. There is not enough info here for me to provide you help.

0 Kudos
Iratxe_Orbe
New Contributor

You are right! sorry

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Iratxe,

   What is this settings object. Small snippets of code like this can prove hard to diagnose without a larger context.

0 Kudos
Iratxe_Orbe
New Contributor

Sorry Robert, this is the complete function

       /*------------------------------------*/
       // Query arcgis items
       /*------------------------------------*/
  queryArcGISGroupItems: function (obj) {
     // default values
     var settings = {
         // set group id for web maps
         id_group: '',
         // type of item
         searchType: this.config.searchType,
         // filter these items
         filterType: '',
         // access type
         searchAccess: '',
         // format
         dataType: 'json',
         // sorting column: The allowed field names are title, modified, type, owner, avgRating, numRatings, numComments and numViews.
         sortField: this.config.sortField,
         // sorting order: Values: asc | desc
         sortOrder: this.config.sortOrder,
         // if pagination
         pagination: true,
         // how many links to show on each side of pagination
         paginationSize: 1,
         // show first and last links on pagination
         paginationShowFirstLast: true,
         // show previous and next links
         paginationShowPrevNext: true,
         // search limit
         perPage: '',
         // maps per row
         perRow: '',
         // offset
         searchStart: 0,
         // search keywords
         keywords: '',
         // style of layout for the results
         layout: 'grid',
         // callback function with object
         callback: null
     };
     // If options exist, lets merge them with our default settings
     if (obj) {
         dojo.mixin(settings, obj);
     }
     var q = '';
     q += 'group:"' + settings.id_group + '"';
     if (settings.keywords) {
         q += ' AND (';
         q += ' title:"' + settings.keywords + '"';
         q += ' OR tags:"' + settings.keywords + '"';
         q += ' OR typeKeywords:"' + settings.keywords + '"';
         q += ' OR snippet:"' + settings.keywords + '"';
         q += ' ) ';
     }
     if (settings.searchType) {
         q += ' AND typekeywords:"' + settings.searchType + '"';
     }
     if (settings.searchType && settings.filterType) {
         q += ' -type:"' + settings.filterType + '"';
     }
     if (settings.searchAccess) {
         q += ' AND access:"' + settings.searchAccess + '"';
     }
     var params = {
         q: q,
         v: this.config.arcgisRestVersion,
         f: settings.dataType
     };
     if (settings.sortField) {
         params.sortField = settings.sortField;
     }
     if (settings.sortOrder) {
         params.sortOrder = settings.sortOrder;
     }
     // TODO FOR UPDATE:
     // MANAGE PAGINATION OF RESULTS
     if (settings.perPage) {
         //params.num = settings.perPage;
         params.num = 100;
     } else {
         params.num = 100;
     }
     if (settings.searchStart > 1) {
          params.start = (((settings.searchStart - 1) * settings.perPage) + 1);
     }
     this.portal.queryItems(params).then(function (data) {
         if (typeof settings.callback === 'function') {
             // call callback function with settings and data
             settings.callback.call(this, settings, data);
         }
     });
  }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Iratxe,

  Are you using a line like this to init your portal object?

this.portal = portalUtils.getPortal(this.appConfig.portalUrl);

0 Kudos
Iratxe_Orbe
New Contributor

Hi Robert,

Yes, I am initialising it as follows:

this.portal = portalUtils.getPortal(this.appConfig.portalUrl);

the portal URL is: http://eea.maps.arcgis.com/

And the this.portal object has been created properly.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Hmm..   So far I am not reproducing your issue.

0 Kudos