print dijit error

983
2
08-16-2012 09:55 AM
MichaelDawson1
New Contributor II
I am currently using the Election Polling Place template application for ArcGIS 10.1.  I have the need to add  a print button to the application. 

Using the sample ???Print dijit Print Templates Created using esri.request??? form the ArcGIs API for JavaScript samples page as a guide, I adjusted the code to handle the  new print button.

When I use this button I am getting the following error in Firebug ???TypeError: sym is Undefined??? this is coming form ?v=2.8compact (line 48)

Anybody know how I might fix this error

Current code I am using


 // get print templates from the export web map task
             var printInfo = esri.request({
             "url": printURL,
             "content": { "f": "json" }
             });
             printInfo.then(handlePrintInfo, handleError);


function handlePrintInfo(resp) {
   
        var layoutTemplate, templateNames, mapOnlyIndex, templates;

        layoutTemplate = dojo.filter(resp.parameters, function(param, idx) {
          return param.name === "Layout_Template";
        });
        
        if ( layoutTemplate.length == 0 ) {
          console.log("print service parameters name for templates must be \"Layout_Template\"");
          return;
        }
        templateNames = layoutTemplate[0].choiceList;

        // remove the MAP_ONLY template then add it to the end of the list of templates 
        mapOnlyIndex = dojo.indexOf(templateNames, "MAP_ONLY");
        if ( mapOnlyIndex > -1 ) {
          var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
          templateNames.push(mapOnly);
        }
        
        // create a print template for each choice
        templates = dojo.map(templateNames, function(ch) {
          var plate = new esri.tasks.PrintTemplate();
          plate.layout = plate.label = ch;
          plate.format = "PDF";
          plate.layoutOptions = { 
            "authorText": "May by:  Esri's JS API Team",
            "copyrightText": "<copyright info here>",
            "legendLayers": [], 
            "titleText": "Pool Permits", 
            "scalebarUnit": "Miles" 
          };
          return plate;
        });

        // create the print dijit
        var printer = new esri.dijit.Print({
          "map": map,
          "templates": templates,
          url: printURL
        }, dojo.byId("print_button"));
        printer.startup();
      }

      function handleError(err) {
   alert(err);
   
        console.log("Something broke: ", err);
      }
0 Kudos
2 Replies
derekswingley1
Frequent Contributor
Somewhere, you're referencing a variable named "sym" without previously defining it. Double-check your code for instances of "sym" and go from there.
0 Kudos
GavinRehkemper
Esri Contributor
I am currently using the Election Polling Place template application for ArcGIS 10.1.  I have the need to add  a print button to the application. 

Using the sample �??Print dijit Print Templates Created using esri.request�?� form the ArcGIs API for JavaScript samples page as a guide, I adjusted the code to handle the  new print button.

When I use this button I am getting the following error in Firebug �??TypeError: sym is Undefined�?� this is coming form ?v=2.8compact (line 48)

Anybody know how I might fix this error



Michael,

I was getting this same error on a project recently (also on the API v2.8), and the problem stemmed from the fact that the selectionSymbol was not set on some of the feature layers we were trying to print. This issue seems to be fixed (i.e. no error if the selectionSymbol is not set) in later (> 2.8) versions of the API.

Our workaround was to set the selection symbol (even if it's a generic SimpleFillSymbol) right before we call printTask.execute(params) on all the featureLayers that did not have it set.

Hope this helps!
0 Kudos