Select to view content in your preferred language

Error using ESRI Print Task service

4755
6
02-28-2013 06:55 AM
JoanSteinbacher
Occasional Contributor
Hi,

I'm encountering an error using the ESRI print task (http://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%2...) that I'm having trouble resolving.

My app is here: http://gis.tpcmaps.org/apps/staging/pima

The error only occurs after the data grid is dislplayed (e.g., via the app's Find Parcel functionality) and I then try to Print.

The apps returns the error:

[INDENT](in Firebug): TypeError: cyclic object value
...="'")){_2f3.matchFor=cmf.slice(1,-1);}}_2f2.attrs.push(_2f3);_2f3=null;_2eb=_2ed...

(in IE developer tools): SCRIPT5034: Circular reference in value argument not supported
PrintTask.js, line 19 character 2208[/INDENT]


The relevant code is:

function doFindParcel(searchText) {
 console.log("-->inside doFindParcel");
   //create query task with url to map service.
 var queryTask = new esri.tasks.QueryTask(configOptions.parcellayer);
 var query = new esri.tasks.Query();
 query.returnGeometry = true;
 query.outSpatialReference = map.spatialReference;
 query.outFields = configOptions.parceloutfields;
 
 console.log("searchText: " + searchText);
    //set the search text to find parameters
    //findParams.searchText = searchText;
 searchby = dijit.byId('searchby').value;
 searchfor = searchText.trim(); //trim the string in case user puts leading spaces in.
 console.log("searchby: " + searchby + ", searchfor: " + searchfor);
 //Search for the keyword at the beginning of the field so it will use the indexes.
 //If search with the wildcard in the front, it does a complete table scan which is slow.
 switch (searchby) {
  case "folio":
     //query.where = "OBJECTID = 1";
     //query.where = "[FOLIO] = '194001.0000'"; 
     //query.where = "[FOLIO] = '" + searchfor + "'"; 
     query.where = "[FOLIO] like '" + searchfor + "%'"; 
     break;
  case "owner":
     query.where = "[OWNER1] like '" + searchfor + "%'";
     break;
  case "site_addr":
     query.where = "[STR_NAME] like '" + searchfor + "%'";
     break;          
 }
 console.log("query where: " + query.where);
    //Show the dialog box to containing "searching" message (so user knows app is doing something).
 dijit.byId("searchingDialog").show();
    queryTask.execute(query, showParcelResults, showParcelError);
}
  
function showParcelResults(results) {
 console.log("-->inside showParcelResults");
   //resultcount = results.length; //this worked for the FindTask, but not for QueryTask.
   //think query task returns result objects but find task returns features?
   resultcount = results.features.length;
   console.log("# of query result objects passed into function: " + resultcount);
   features = results.features;

 //Close the 'searching' dialog box. 
 dijit.byId("searchingDialog").hide();

 if (resultcount > 0) {
  //console.log("-->inside resultcount loop");
  //Open the dialog box to display results in a grid. 
  showResultsGrid(features);   
 }
 //Alert user in case parcel is not found, 9/11/12 jms.
 else {
  dialogAlert("Find Parcel", searchby + ": " + searchfor + " was not found.");
 }
}

function showParcelError(error) {
 //Close the 'searching' dialog box. 
 dijit.byId("searchingDialog").hide();
 console.log("Find Parcel", "Error in 'Find Parcel': " + error);
 dialogAlert("Find Parcel", "Error in 'Find Parcel': " + error);
}

//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt){
 console.log("-->inside onRowClickHandler");
    var clickedTaxLotId = grid.getItem(evt.rowIndex).FOLIO;
    var selectedTaxLot;
    var symbol = new esri.symbol.SimpleFillSymbol(highlightfillSymbol);

    dojo.forEach(map.graphics.graphics,function(graphic){
      if((graphic.attributes) && graphic.attributes.FOLIO === clickedTaxLotId){
       //Setting the symbology here sets it for only the feature clicked on.
  graphic.setSymbol(symbol);
        selectedTaxLot = graphic;
        return;
      }
    });
    var taxLotExtent = selectedTaxLot.geometry.getExtent();
    map.setExtent(taxLotExtent);
}

function showResultsGrid(features) {
 //This function works with an array of result that the task returns
 console.log("-->inside showResultsGrid");
 console.log("# of features passed into function: " + features.length);
 var resultcount = features.length;


 //Open the dialog box to display results in a grid.   
 dijit.byId("parcelresultsDialog").show();
 
 //Display number of results in the dialog box header.
 dojo.byId('rowcountdisplay').innerHTML=resultcount+" parcels.<br/>"+ configOptions.selectparcelnote + configOptions.maxrecordcount + ".";
 
 //map.graphics.clear();
 //clearAllGraphicsLayers();
 
 //var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98, 194, 204]), 2), new dojo.Color([98, 194, 204, 0.5]));
 var symbol = new esri.symbol.SimpleFillSymbol(resultfillSymbol);

 //create array of attributes and add graphic to map.
 items = dojo.map(features, function(feature){
  //console.log("-->inside create array of attributes");
  //var graphic = result.feature;
  var graphic = feature;
  //Setting the symbology here sets it for all features in results.
  graphic.setSymbol(symbol);
  map.graphics.add(graphic);
  //console.log("after adding graphic");
  return feature.attributes;
 });
 
 //Create data object to be used in store
 var data = {
  identifier: "FOLIO", //This field needs to have unique values
  label: "FOLIO", //Name field for display. Not pertinent to a grid but may be used elsewhere.
  items: items
 };
 
 //Create data store and bind to grid.
 var store = new dojo.data.ItemFileReadStore({ 
  data: data
 }); 
 
 //Grid used in the results pop-up dialog.
 grid = dijit.byId('grid');
 grid.setStore(store);
 
 //Grid used for exporting the data (containing additional fields) to a csv file.
 var gridexport = dijit.byId('gridexport');
 gridexport.setStore(store);
 
}


I have no idea what the problem is or how to debug this. Can anyone assist or offer suggestions?

Thanks in advance,
Joan
0 Kudos
6 Replies
KellyHutchins
Esri Frequent Contributor
The problem is that the same graphic is used by the data grid (the attributes) and displayed in the map. The print task serializes the graphics to JSON which doesn't support the cyclic structure.

To avoid this problem try creating a copy of the graphic to add to the map using the following:


   var graphic = new esri.Graphic(result.feature.toJson());


I've attached a working demo that shows this approach.
0 Kudos
JoanSteinbacher
Occasional Contributor
Kelly,

Thanks so much for the reply and the sample code. I implemented it and it seems to work perfectly. I really appreciate your help as I don't think I ever would have figured it out on my own!

Joan
0 Kudos
ThomasHynes
Occasional Contributor
Had the same problem here and this .toJSON() fixed it.
0 Kudos
KaushalShah
Emerging Contributor
Had the same problem here and this .toJSON() fixed it.


This helped me too. Thanks.

Regards,
Kaushal Shah.
0 Kudos
IrfanClemson
Frequent Contributor
Hi,
This thread has also helped me to fix the Print problem. Much thanks!
But now my Info Window popups' 'title' just show 'R' as title. Here was my code before and after:

var graphic = results.features;//old

var graphic = new esri.Graphic(results.features.toJson());//new

So how can I fix this problem? So far I can't find anywhere I am setting up InfoWindows content/title being setup and may be the first attribute becomes the title--except now it is messed up.

TIA!
0 Kudos
IrfanClemson
Frequent Contributor
Never mind: I fixed the Info Window title problem by encoding the title text differently.
Thanks.
0 Kudos