Geoprocessing Task

366
3
Jump to solution
09-17-2019 07:32 AM
jaykapalczynski
Frequent Contributor

Please Help

I am trying to run a GP task from a test Appstudio app.

This is what I have right now and want to see if I am on the right path....as this varies from the JavaScript API

1. ALL I am trying to do is Pass a few variables on a button click to the GP service.

2. Once at the GPS Service I want to write those to Variables.

I just want to make sure I can transfer this data and grab it on the back end.  

Right now I am referencing an ESRI same service I will replace this with mine.

// snip

    property GeoprocessingJob viewshedJob: null

// snip


    // ON BUTTON CLICK I WILL LAUNCH THIS
    // viewshedTask.calculateViewshed(mouse.mapPoint);
    

    
    GeoprocessingTask {
        id: viewshedTask
        url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed"
            
       function calculateViewshed(location) {     
            var viewshedParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters", {
                            executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute
            });            
            
            var ObjectID = "65421"   // will get these values from textboxes 
            var Comments = "something"  // will get these values from textboxes 
            
            var params = {"OBHECTID":ObjectID,"comments":Comments };
            
            viewshedParameters = params;
           
            // Create the job that handles the communication between the application and the geoprocessing task
            viewshedJob = viewshedTask.createJob(viewshedParameters);
            
            // Create signal handler for the job
            viewshedJob.jobStatusChanged.connect(viewshedJobHandler);
    
            // start the job
            viewshedJob.start();
       }    
    }    

import arcpy
import os


# Geting user input for project name, status, type, submital date and planner name  
varObjectID = arcpy.GetParameterAsText(0)  
varComments = arcpy.GetParameterAsText(1) 



# do something with the returned values 





0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

I figured it out....had to add "submitJob" to my URL

url: "https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun"
url: "https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun/submitJob"



    GeoprocessingTask {
        id: updateCursorTask
        url: "https://xxx/arcgis/rest/services/Tools/Update/GPServer/NewScriptToRun/submitJob"


            var gpParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
                    {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute});

            var inputs = {};
            inputs["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem, objectName: varItem});
            inputs["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varPublicPrivate});


            var inputresults = inputs;
            gpParameters.inputs = inputs;

            // Create the job that handles the communication between the application and the geoprocessing task
            updateCursorJob = updateCursorTask.createJob(gpParameters);
            updateCursorJob.start();

View solution in original post

0 Kudos
3 Replies
jaykapalczynski
Frequent Contributor

I created a Toolbox

I created a New Script

I then set parameters for each of the fields I want to update

I then modified the python file as such:

When I run the tool I can add values in the attribute fields from the popup window and it updates fine...

I just don't know how to pass the parameters from inside AppStudio to the GP Service.....

import arcpy
from arcpy import env
import os

# Geting user input for project name, status, type, submital date and planner name  
varObjectID = arcpy.GetParameterAsText(5) 
varItem = arcpy.GetParameterAsText(0)  
varPublicPrivate = arcpy.GetParameterAsText(1)  
varCaseNum = arcpy.GetParameterAsText(2)  
varComments = arcpy.GetParameterAsText(3)  
varClassification = arcpy.GetParameterAsText(4)
varLast_created_user = arcpy.GetParameterAsText(6)
varLast_edit_date = arcpy.GetParameterAsText(7)
  
#Set variable to hold SQL statement to query out project to update  
whereClause = "[OBJECTID] = '{0}'".format(varObjectID)

fc = 'Data.DBO.Incidents'
workspace = arcpy.env.workspace = r'C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\editor@credentials.sde'

# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)

# Edit session is started without an undo/redo stack for versioned data
#  (for second argument, use False for unversioned data)
edit.startEditing(False, False)

# Start an edit operation
edit.startOperation()

# UPDATE a row in the Feacture Class
Ucursor = arcpy.da.UpdateCursor(fc,["OBJECTID","Item","PublicPrivate","CaseNum","Comments","Classification","last_edited_user", "last_edited_date"],whereClause)
for row in Ucursor:  
    irow = (varObjectID, varItem, varPublicPrivate, varCaseNum, varComments, varClassification, varLast_created_user, varLast_edit_date)  
    Ucursor.updateRow(irow)  
arcpy.RefreshActiveView()  

# Stop the edit operation.
edit.stopOperation()

# Stop the edit session and save the changes
edit.stopEditing(True)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

I have a GP Service running and I can input values and it works great...running it manually on the server

I just cant figure out how to call that Service from AppStudio and pass it the input parameters.

I cant find an example anywhere....please help

0 Kudos
jaykapalczynski
Frequent Contributor

I figured it out....had to add "submitJob" to my URL

url: "https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun"
url: "https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun/submitJob"



    GeoprocessingTask {
        id: updateCursorTask
        url: "https://xxx/arcgis/rest/services/Tools/Update/GPServer/NewScriptToRun/submitJob"


            var gpParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
                    {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute});

            var inputs = {};
            inputs["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem, objectName: varItem});
            inputs["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varPublicPrivate});


            var inputresults = inputs;
            gpParameters.inputs = inputs;

            // Create the job that handles the communication between the application and the geoprocessing task
            updateCursorJob = updateCursorTask.createJob(gpParameters);
            updateCursorJob.start();
0 Kudos