|
POST
|
Trying to consume a Geoprocessing Service (webtool) out of ArcGIS Pro with JSAPI 3.31 in WAB DE. I have geoprocessing service that's supposed to prepare a web map for printing. This was adapted from the example given in the documentation here - ConvertWebMapToArcGISProject—ArcPy | Documentation. Service is consumed from JSAPI (WAB widget) and would like users to be able to save/open the resulting PDF from the app. The service readily produces PDF output in a server directory but every attempt to return some reference to it (as file or filepath) so that I can interact with it in Javascript has failed so far. Numerous other Geonet threads have suggested various fixes, and I've tested them all. The error I get consistently points to the setting of parameter: RuntimeError: Object: Error in setting parameter as text
Failed to execute I've tried both arcpy.SetParameter()
and
arcpy.SetParameterAsText(). In my geoprocessing tool, I've tried type "String" with "SetParameterAsText" and passing the path to the file, and I've tried type "File" with "SetParameter" and passing a reference to the actual file. I've tried creating the file in arcpy.env.scratchWorkspace as suggested in one thread, then doing the following to get a proper i/o file reference to it (as suggested elsewhere): uniqueID = str(uuid.uuid1())
WebMapPDF = os.path.join(arcpy.env.scratchWorkspace, 'WebMap_{0}.pdf'.format(uniqueID))
layout.exportToPDF(WebMapPDF)
PDFOutputFile = open(WebMapPDF_forDownload)
PDFOutputFile.close()
arcpy.SetParameter(1, PDFOutputFile.name) # I only have one GetParameter, so this is index 1
In JS, I was hoping to do something like this with a reference to the file: gp.getResultData(jobInfo.jobId, "PDFOutputFile", this.printComplete);
},
printComplete : function(result) {
window.open(result.url);
}, but haven't even gotten as far as getting an error because the geoproc service call keeps failing. As stated above, replacing the scratchspace reference with an actual server path and removing the setparameter, creates a beautiful PDF. So thee issue has to be with my last line of Python that set the output parameter or with configuring that parameter in the tool. Or potentially in how these get passed into the widget? Here is how I set up my Geoprocessor parameters.... var gpParams = {"Web_Map_as_JSON" : webMapAsJSON};
// do I need to include my PDFOutfile in the params ?
// var gpParams = {"Web_Map_as_JSON" : webMapAsJSONasString,
// "PDFOutputfile" : call it what?? };
gp.submitJob(gpParams, this.completeCallback, this.statusCallback);
... View more
02-12-2020
08:15 AM
|
0
|
1
|
2084
|
|
POST
|
I think you might have to actually run Pro once as the user that will run your script. I remember something like that I had to do recently.
... View more
02-07-2020
01:56 PM
|
0
|
0
|
1194
|
|
POST
|
Thanks, Ken... looks very intriguing but probably a little more than I need right now. I will come back to this though. Appreciate your time responding!!
... View more
02-05-2020
11:54 AM
|
0
|
0
|
7830
|
|
POST
|
Well, that was easy! - Haha. So I was looking for a way to do something that you don't or can't do. As for the vanilla vs. dojo, yes, I understand. Reading dojo documentation cleared that up. Got the select working now, and once I remembered to instantiate as "this.mySelect" instead of saying "var mySelect", the last domino fell in place. (And, if you remember the last thread, now i can get to my selected value in the Select and tie that in with my Select getting populated from a service.) Thanks a bunch, Robert!
... View more
02-05-2020
11:53 AM
|
0
|
0
|
7830
|
|
POST
|
Ken Buja.Robert Scheitlin, GISP - Guys, I have spawned a new thread from this so as not to stray too far in my questioning from the original title here. Feel free to chime in again! really appreciate all your input so far. You don't know how helpful this is!!!
... View more
02-05-2020
09:56 AM
|
0
|
0
|
1084
|
|
POST
|
The title of this thread may be confounding to someone who either has either never heard of dojo attach or else has long ago mastered the science of dojo. I have been trying to wrap my brain around some of it, and am forking this from a separate thread. Thanks for Robert Scheitlin, GISP and Ken Buja for chiming in there. Full disclosure: I'm working within the confines of widget.cs/widget.html trying to build custom widgets for WAB. So I may be falsely attributing behavior or issues to Dojo that are actually rooted in some of the jimu overhead that I'm inheriting. Say, you have a super simple widget.html that looks like this: <div id="main" data-dojo-attach-point="main"> (The following code snippets come from my startup function in widget.js. ) I thought i would be able to create a new div inside "main" as follows: var existingDiv = document.getElementById("main");
var newDiv = document.createElement("div");
existingDiv.appendChild(newDiv);
var newStuff = document.createTextNode("Such a pretty Div");
newDiv.appendChild(newStuff); But that doesn't work. TypeError: Cannot read property 'appendChild' of null So, regardless of what 'id' I give my element, it gets assigned an id that looks something like this: widgets_MyNewWidget_Widget_19 Wow, once I figured that out and used the above as id, appendChile works just fine. Much simpler even using the dojo/dom-construct and the data-dojo-attach-point is to do this: domConstruct.place("<div>dojo created div</div>",this.main,"last") Now, I want to create something a little more useful than just a text div. I want to have a dropdown to select from. define([...,"dijit/form/Select",...],
function(...,Select, ...)
...
var mySelect = new Select({
name: 'myselect',
dropDown: true,
options : [
{label: 'Bernie',value: "Option1"},
{label: 'Buttie',value: "Option2"},
{label: 'Bidey',value: "Option3"}
]
},<needs some id here>);
Oh, wait now, my new <dojo-created-div> needs an id to know where to go. If I use "main", nothing happens. I don't see my select. if I use the "widgets_MyNewWidget..." as 'id', I get an error: Tried to register widget with id==widgets_MyNewWidget_Widget_19 but that id is already registered So instead, I add a new 'id' to my domConstruct: domConstruct.place("<div>id='newdiv' dojo created div</div>",this.main,"last") Now, I can use the "newdiv" id inside the definition of the new Select, and it gets created. Now, here is the problem I haven't figured out how to solve. On my event listeners, previously when the select would have been set up as <select> in HTML, I have been using something like: on(this.myselect,"change",lang.hitch(this, function(evt){
console.log("select has changed);
})); ... where again, 'myselect' would be a reference to a dojo-attach points. So now I am trying to figure out if there is a way to create the attach point programmatically. I've tried adding it to the domConstruct.place(): domConstruct.place("<div data-dojo-attach-point='myselect' id='newdiv'></div>",this.main,"last"); That doesn't work. I've also tried the following once the Select has been created: mySelect.set("data-dojo-attach-point","myselect");// - doesnt' work That doesn't work either, likely because ... set() and get() In general attributes can be both set at initialization and modified after the widget is created, although some attributes, like “id” and “type”, which are marked [const]... (from Dojo documentation) So is there a way to do this in javascript? Or do I have to set this up in my HTML? And if so, how do I do it? Every time I create another HTML element to contain my programmatically created Select, the Select shows up but I can't reference it using "this.myselect". What am I doing wrong? What's the best practice that get the best of both worlds - hrml and javascript - in this case?
... View more
02-05-2020
09:53 AM
|
0
|
4
|
8389
|
|
POST
|
I had to back several iterations after jacking up all my widiget code. Originally, I had MultiSelect in there. But I've switched again to Select. I spent a lot of time yesterday reading up on dojo vs dom ways to interact with the page elements. For example,.. document.getElementById() dojo.byId() dijit.byId() That cleared up some misunderstanding. Now, I have figured out how to create my elements programmatically and placing them inside elements identified with data-dojo-attach-point. The question I'm trying to answer now is whether i can create a new elements and set a data-dojo-attach-point programmatically. But I'll move that line of questioning into a more focused thread. Thanks to both of you for chiming in so patiently.
... View more
02-05-2020
08:06 AM
|
0
|
1
|
9498
|
|
POST
|
Ken, Here is my very stripped down HTML. <input data-dojo-type="dojox/mobile/SearchBox" data-dojo-attach-point="siteSearch" type="search" placeHolder="Search">
<input data-dojo-attach-point="searchBtn" type="button" value="Search for this Wellsite ">
<select data-dojo-attach-point="results" class="text-box-scroll" data-dojo-type="dijit/form/MultiSelect"></select> It is working fine until l make Robert's suggested change of adding _WidgetsInTemplateMixin to the declare. I suspect I'm still not setting my dojo elements up correctly and just adding that dojo-attach point is not sufficient. Time to read up on Dojo, I guess.
... View more
02-04-2020
01:57 PM
|
0
|
3
|
9498
|
|
POST
|
The only reason I asked after having good success with the dojo-attach was because I keep coming across code snippets from you that use the dom,.byId - haha. I do have "dijit/form/Select" in my defines. But I suspect, I'm not setting up the dijit correctly, i.e. not creating it programmatically like I should. define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
[...]
"dojo/_base/lang",
"dojo/on",
"dojo/dom",
"dijit/form/Select"],
function(declare,
BaseWidget,
_WidgetsInTemplateMixin,
[...]
lang,
on,
dom,
Select)
... View more
02-04-2020
11:42 AM
|
0
|
1
|
9498
|
|
POST
|
Thanks for sharing, Ken. At first glance, it looks very similar to what I had. You have a <div> with a dojo-attach point. I had a <select>. If I drop mine for the div, I love my scrollbar. I was setting up my options like this: var c = document.createElement('option');
this.results.appendChild(c); You used removeOption(), I had: while (this.results.firstChild) {
this.results.removeChild(this.results.firstChild);
}; If I try option = {value: myAttrVal,
label: myAttr}
this.results.addOption(option); I get init.js:115 TypeError: this.results.addOption is not a function if I keep my createElement/appendChild,instead of addOption, I end up with: init.js:115 TypeError: this.results._setDisplay is not a function I'll take another look at Robert's to make sure I am working with a "real' dojo dijit. -- I have a stack of dojo books on my desk...I think I need to spend a week just reading them. haha.
... View more
02-04-2020
11:35 AM
|
0
|
5
|
9498
|
|
POST
|
Thanks, Renee. - For anyone needing more info, there is a somewhat more recent related thread here: Get the WebMap from Javascript API esri/map
... View more
02-04-2020
10:31 AM
|
0
|
0
|
2809
|
|
POST
|
So I had always hoped to avoid the whole dojo universe. The JSAPI 4.x seems to more and more inoculate against the inner workings of whatever dojo its using. But now, I'm trying to build some custom WAB widgets and see myself having unscramble some of this dojo stuff. i got a 2-part question, and question subject refers to only part 2. Part 1 Robert Scheitlin, GISP had some advice suggesting to work with dojo attachments points, as in ... <input data-dojo-attach-point="myButton" type="button" value="Click Here"> so that in my code I could refer to this element in widget.html simply as this.myButton. But I'm still not sure when to use the above or - provided I have added id = 'myButton', use this; dom.byId("myButton") I see folks using them almost interchangeably through this forum and elsewhere. Are there some simple guiding principles? Part 2 Now for the Select. I'm making a call to a web service, ignoring geometry and just returning the feature's name. Then I populate a <select> with that, which I have called: <select id='results' data-dojo-attach-point='results' data-dojo-type="dijit/form/Select"></select> The following code populates a bunch of entries (or <option>'s) in that <select> with records from the service. //Interate over features in featureset
//find desired feature attribute's value
{
var c = document.createElement('option');
c.innerHTML = myAttributeValue;
c.value = i;
this.results.appendChild(c); // 'results' being my dojo attach point
} Next, I would like to use the dijit's event listener to watch if one of those <options>'s is selected. Again, ... on(this.results,"change",lang.hitch(this, function(evt){
console.log(this.results); The above gets me a reference to the <select> but no attempt - such as ".value",".displayValue", "_getDisplayedValueAttr()" or ".selected" has been successful in getting me the value that's selected, and I've scoured the Dojo site for info. I can iterate over this.results.options and check the attribute selected for each one, but is there a simpler way? Thanks.
... View more
02-04-2020
08:48 AM
|
0
|
10
|
11305
|
|
POST
|
Yes, yes, yes ... so right. I thought I didn't need it, so I took it out. But... Next, I couldn't explain why I can reference and udpate a "data-dojo-attach-point" from within the onOpen() method but was aggravatingly unable to do so from within the showResults() method. Well, because it wasn't getting passed the reference to the widget scope. I think I'm beginning to understand this.And all the sudden the door opens to all those examples out there you've been saying we should study to understand the custom widget world! Thank you!
... View more
01-30-2020
11:50 AM
|
1
|
0
|
3730
|
|
POST
|
Thank you, WAB Jedi Master! That was great. A few comments... Thanks for reminding me to use the "dojo-attach-point" instead of "id". You said the same in your last reply on another thread, and I didn't heed the advice. But I guess - judging from my study of gazillions of threads here - that's the story of your life - haha - repetition. I'll try to remember going forward. Also, now I don't need the dom.ById reference any more. Moved my execute(0 and showresults) into the widget's scope. Moved the query set up into postCreate(). Only thing left in onOpen() is the event listener/handler. Only thing I had to tweak from your code, based on my above changes was in the execute() function: Yours: this.queryTask.execute(query, lang.hitch(this, this.showResults)); Mine: this.queryTask.execute(this.query, this.showResults); Thanks for helping me along wrapping my brain around some of this scoping stuff. I might create another thread asking for feedback on the best primers on some of these concepts. I've read a handful. But there may be betters ones. Again, I think you should write a book!
... View more
01-30-2020
09:28 AM
|
0
|
2
|
3730
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-16-2025 07:32 AM | |
| 1 | 02-09-2024 05:18 PM | |
| 1 | 02-04-2025 09:27 AM | |
| 1 | 03-22-2019 10:55 AM | |
| 1 | 03-05-2020 08:46 AM |
| Online Status |
Offline
|
| Date Last Visited |
a month ago
|