Problem accessing custom text elements in my print service

3079
12
Jump to solution
06-05-2013 12:53 PM
TracySchloss
Frequent Contributor
I created a copy of the basic exportmaptemplates to make my own custom layout.  I needed to add both subtitles and descriptive text to my layout.  I added two new text elements and gave them element names of subTitleText and descripText.  Just to have something to see on my map, because I'm going to change these programmatically, I've given them a text value the same as the element name.

I didn't receive any errors when I published this print service, so I'm thinking the service itself is OK?  I'm having some problems with the syntax of referencing these new elements.

I'm using the JS API, and in Firebug, I can see the call getting made to the print service.  It includes the custom text elements by their element names, with the values that got assigned in my code.  I am getting an error in my JS code, but if I copy/paste the string that's getting submitted to the print URL, it does generate output.  It just doesn't include the new values I'm assigning for subTitleText and descripText.  It's still just the default string I put in as a placeholder.

 {"mapOptions":{"showAttribution":true,"extent":{"xmin":-10391169.27082235,"ymin":4469925.719133955,"xmax":-10383726.21519309,"ymax":4476250.883224546,"spatialReference":{"wkid":102100}},"spatialReference":{"wkid":102100},"scale":36111.90964300888},"operationalLayers":[{"id":"streetMap","title":"streetMap","opacity":1,"minScale":591657527.591555,"maxScale":1128.497176,"url":"http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"},{"id":"countyLayer","title":"countyLayer","opacity":1,"minScale":0,"maxScale":0,"url":"https://ogitest.oa.mo.gov/ArcGIS/rest/services/BaseMap/county_simple/MapServer","visibleLayers":null,"layers":[]},{"id":"status_stateOwnParcelLayer","title":"status_stateOwnParcelLayer","opacity":1,"minScale":0,"maxScale":0,"url":"https://ogitest.oa.mo.gov/ArcGIS/rest/services/StateOwnedParcels/MapServer","visibleLayers":null,"layers":[]},{"id":"allParcelLayer","title":"allParcelLayer","opacity":1,"minScale":0,"maxScale":0,"url":"https://ogitest.oa.mo.gov/ArcGIS/rest/services/allParcels/MapServer","visibleLayers":null,"layers":[]},{"id":"stateOwnFeaturelayer","url":"https://ogitest.oa.mo.gov/ArcGIS/rest/services/StateOwnedParcels/MapServer/1","title":"stateOwnFeaturelayer","minScale":1155581,"maxScale":0,"layerDefinition":{"drawingInfo":{"renderer":{"type":"simple","label":"","description":"","symbol":{"color":[255,211,127,255],"outline":{"color":[110,110,110,255],"width":0.4,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}}}}},{"id":"mapDiv_graphics","minScale":0,"maxScale":0,"featureCollection":{"layers":[{"layerDefinition":{"name":"polygonLayer","geometryType":"esriGeometryPolygon"},"featureSet":{"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-10387278.9405581,4472649.14459539],[-10387279.6215167,4472629.95429174],[-10387325.6367082,4472631.12368592],[-10387325.6625458,4472633.30616325],[-10387325.8529157,4472641.81899572],[-10387325.6180643,4472650.3308426],[-10387278.9405581,4472649.14459539]]],"spatialReference":{"wkid":102100}},"symbol":{"color":[33,237,254,13],"outline":{"color":[33,237,254,255],"width":2.25,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}}]}}]}}],"exportOptions":{"outputSize":[800,1100],"dpi":96},"layoutOptions":{"titleText":"just something","customTextElements":{"descripText":"BEG 192.1 FT S SE COR KANSAS & KEARNEY STS S 50 FT E 160 FT N 50 FT W TO BEG11/29/22 (EX W 20 FT)","subTitleText":" 2331 N KANSAS AVE"},"scaleBarOptions":{"metricUnit":"Kilometers","metricLabel":"km","nonMetricUnit":"Miles","nonMetricLabel":"mi"},"legendOptions":{"operationalLayers":[]}}}


Am I misunderstanding how to include these custom text elements?  Should they not be nested within the layoutOptions the way I have them?  Sorry about the big long JSON string, that's just the way it came out when I copied from Firebug.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
TracySchloss
Frequent Contributor
I was told by ESRI that 'it shouldn't matter whether my print service was defined as synchronous or asynchronous'.  However, when I change my service to be synchronous, it started working for me.

View solution in original post

0 Kudos
12 Replies
AlexeyTereshenkov
Regular Contributor III
Tracy, can't comment anything on that right now, but I had some issues with printing a legend with the PrintingTools service in 10.1 myself and all the problems I had were solved with the SP1. Have you installed the one?
0 Kudos
TracySchloss
Frequent Contributor
I don't know what else might have been fixed in SP1, but it is installed.
0 Kudos
TanuHoque
Esri Regular Contributor
Tracy,
Custom text elements need to be defined as separate objects, then they need to be put in an array before assigning that array to the layoutOptions.customTextElements property.
http://developers.arcgis.com/en/javascript/jsapi/printtemplate.html#layoutoptions

here is a snippet of how JS code should look like:
template.layoutOptions = {
  titleText: "just something",
  customTextElements: [
    { "descripText": "BEG 192.1 FT S SE COR KANSAS & KEARNEY STS S 50 FT E 160 FT N 50 FT W TO BEG11/29/22 (EX W 20 FT" },
    { "subTitleText": " 2331 N KANSAS AVE" }
  ]
};


here is the equivalent JSON gets sent to a Printing service:
"layoutOptions": {
  "titleText": "just something",
  "customTextElements": [
    {
      "descripText": "BEG 192.1 FT S SE COR KANSAS & KEARNEY STS S 50 FT E 160 FT N 50 FT W TO BEG11/29/22 (EX W 20 FT)"
    },
    {
      "subTitleText": " 2331 N KANSAS AVE"
    }
  ]
}


hope this helps.
0 Kudos
TracySchloss
Frequent Contributor
That's how I have it, except that I have a little punctuation problem.  I'm trying to update the customTextElements in onPrintStart, right before the print is submitted.  When I do, I end up generating
"layoutOptions":{"titleText":"my map title",
"customTextElements":[
{"legalDescriptionText":"BEG 82.5 FT E NE COR BENTON & WALNUT STS E 82.5 FT N 267 FT W 82.5 FT S TO BEG"},
{"subTitleText":" E WALNUT ST"}]


I'm having a real hard time spotting the typo, but I think I'm missing an ending curly brace to close out value of layoutOptions.  Since I'm defining this programmatically, I haven't found the line yet where I can correct this.  I have posting on the JS forum too.  I'm still trying to decide if my service is OK. I'm having a really hard time testing it without programming something.

I found a posting to modify the template to dynamically alter the title, so the user could enter what they wanted.  This added the line
this.templates.layoutOptions.titleText = printTitle;


Then I wanted to go back and also add customTextElements. I ended up with:
        dojo.connect(printer, "onPrintStart", function(){
//console.log("onPrintStart: fullLegalString = " + fullLegalString + "print_subTitle = " + print_subTitle);
            var printTitle = dojo.byId("txtTitle").value;
                for (var i = 0; i < templates.length; i++) {
                   this.templates.layoutOptions.titleText = printTitle;
                 this.templates.layoutOptions.customTextElements =[
                        {"legalDescriptionText": fullLegalString}, 
                        {"subTitleText": print_subTitle} ];  
                }
        });


Maybe instead of trying to define titleText and customTextElements separately, I should try defining the entire layoutOptions and concatenate it all together somehow.  Otherwise I'm still chasing down a curly brace (I think ...)
0 Kudos
TanuHoque
Esri Regular Contributor
I'm having a real hard time spotting the typo, but I think I'm missing an ending curly brace to close out value of layoutOptions.

I'm not an expert in JS, but i thought you'd have got an run-time error if you had any missing ending curly braces. I'm not sure which IDE you are using to write JS code. But as you know you can search the web with "Javascript lint" and use one of those online lint apps to find those syntactical errors.

And as always, as you did in the other case, you can use
console.log(this.templates.layoutOptions)
to make sure that object looks good.

I'm still trying to decide if my service is OK. I'm having a really hard time testing it without programming something.

in order to find out whether you service is ok, you can go to the REST end point of your printing service's task, paste the JSON generated by your app (if you need to fix the missing braces or something like that, fix it, you use some sites like jsonlint.org to check the validity of the json) in ExportWebMap_As_JSON text box, specify the name of the Layout Template and click Execute.


One thing that I noticed (not a bug or error) is that in your code, you are updating layoutOptions for all templates! do you need
to do that? If I'm not mistaken, I think you should update layoutOptions only for the selected template, not all.
0 Kudos
TracySchloss
Frequent Contributor
Yes I mean to have the same custom text elements for both templates.  I don't have this fully populated because I'm just working on a landscape printout, but I'll need a Portrait equivalent with the exact same content.  The user will have to determine which orientation works best for the particular screen content.

I switched my print service from Asynchronous to Synchronous and that seems to have made the difference.  (Although I still think it's gremlins.)  In the instructions for authoring it suggested you can use either for your Execution Method.  I didn't find that was the case!
0 Kudos
TanuHoque
Esri Regular Contributor
I switched my print service from Asynchronous to Synchronous and that seems to have made the difference. (Although I still think it's gremlins.) In the instructions for authoring it suggested you can use either for your Execution Method. I didn't find that was the case!


Hmm... that shouldn't make any difference. You should use async only when you think it may take longer to generate output.
I'd recommend you to contact Esri Tech Support to submit an incident and have them check why async vs sync makes all the difference in your case.

Thanks.
0 Kudos
TracySchloss
Frequent Contributor
I had an open ticket with them, but the choice of synchronous vs. asychronous wasn't suggested as a cause to my problem.
0 Kudos
TracySchloss
Frequent Contributor
I was told by ESRI that 'it shouldn't matter whether my print service was defined as synchronous or asynchronous'.  However, when I change my service to be synchronous, it started working for me.
0 Kudos