Error using ESRI Print Task service

02-28-2013 06:55 AM
New Contributor III

I'm encountering an error using the ESRI print task ( that I'm having trouble resolving.

My app is here:

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

(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 + "%'"; 
  case "owner":
     query.where = "[OWNER1] like '" + searchfor + "%'";
  case "site_addr":
     query.where = "[STR_NAME] like '" + searchfor + "%'";
 console.log("query where: " + query.where);
    //Show the dialog box to containing "searching" message (so user knows app is doing something).
    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. 

 if (resultcount > 0) {
  //console.log("-->inside resultcount loop");
  //Open the dialog box to display results in a grid. 
 //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. 
 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);

      if((graphic.attributes) && graphic.attributes.FOLIO === clickedTaxLotId){
       //Setting the symbology here sets it for only the feature clicked on.
        selectedTaxLot = graphic;
    var taxLotExtent = selectedTaxLot.geometry.getExtent();

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.   
 //Display number of results in the dialog box header.
 dojo.byId('rowcountdisplay').innerHTML=resultcount+" parcels.<br/>"+ configOptions.selectparcelnote + configOptions.maxrecordcount + ".";
 //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 =, 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.
  //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{ 
  data: data
 //Grid used in the results pop-up dialog.
 grid = dijit.byId('grid');
 //Grid used for exporting the data (containing additional fields) to a csv file.
 var gridexport = dijit.byId('gridexport');

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

Thanks in advance,
0 Kudos
6 Replies
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
New Contributor III

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!

0 Kudos
New Contributor III
Had the same problem here and this .toJSON() fixed it.
0 Kudos
New Contributor
Had the same problem here and this .toJSON() fixed it.

This helped me too. Thanks.

Kaushal Shah.
0 Kudos
Occasional Contributor II
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.

0 Kudos
Occasional Contributor II
Never mind: I fixed the Info Window title problem by encoding the title text differently.
0 Kudos