Determine if there is an active Workflow Manager connection
// determine if there is an active Workflow Manager connectionvarisConnected=WorkflowClientModule.IsConnected;// Use the value of isConnected to determine if you can proceed with Workflow Manager operations
Get the Workflow Manager item Id
// Get the Workflow Manager item IdvaritemId=WorkflowClientModule.ItemId;// Use the itemId to identify the Workflow Manager item
Get the Workflow Manager server url
// Get the Workflow Manager server urlvarserverUrl=WorkflowClientModule.ServerUrl;// Use the serverUrl to identify the Workflow Manager server
Get the job Id associated with the active map view
// Get the job Id associated with the active map viewvarjobManager=WorkflowClientModule.JobsManager;jobId=jobManager.GetJobId();// Use the jobId to identify the job associated with the active map view
Get the job Id associated with a map
// Get the job Id associated with a mapvarjobManager=WorkflowClientModule.JobsManager;jobId=jobManager.GetJobId(mapUri);// Use the jobId to identify the job associated with the map
Get the job Id associated with a running OpenProProjectItems step
// Get the job Id associated with a running OpenProItems step for a Pro Add-In module// In the Add-In Module class, override the ExecuteCommandArgs(string id) method and return a Func<Object[], Task> object like the sample below// Refer to the Workflow Manager ProConcepts Sample Code link for an exampleFunc<object[],Task>overrideFunction=(args)=>QueuedTask.Run(()=>{try{// Get the jobId property from the OpenProProjectItemsStep arguments and store it.OpenProProjectItemsStepCommandArgsstepArgs=(OpenProProjectItemsStepCommandArgs)args[0];varjobId=stepArgs.JobId;ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"Got job id from ProMappingStep args: {jobId}","Project Info");// Run the command specified by the id passed into ExecuteCommandArgsIPlugInWrapperwrapper=FrameworkApplication.GetPlugInWrapper(id);if(wrapperisICommandcommand&&command.CanExecute(null))command.Execute(null);}catch(Exceptione){ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"ERROR: {e}","Error running command");}});// Use overrideFunction to get the jobId from the step args when the command is executed
Get a job
// Note: QueuedTask is required to call Workflow Manager API methods// GetJob returns an existing jobtry{varjobManager=WorkflowClientModule.JobsManager;varjob=jobManager.GetJob(jobId);// Do something with the job}catch(NotConnectedException){// Not connected to Workflow Manager server, do some error handling}catch(Exception){// Some other exception occurred, do some error handling}// Use the job object
Search for jobs using a detailed query
varsearch=newSearchQuery(){// Search for all open high priority jobs assigned to usersQ="closed=0 AND assignedType='User' AND priority='High'",Fields=["jobId","jobName","assignedTo","dueDate"],// Sort by job assignment in ascending order and due date in descending orderSortFields=[newSortField(){FieldName="assignedTo",SortOrder=SortOrder.Asc},newSortField(){FieldName="dueDate",SortOrder=SortOrder.Desc}]};varjobManager=WorkflowClientModule.JobsManager;varsearchResults=jobManager.SearchJobs(search);varfields=searchResults.Fields;varresults=searchResults.Results;
Search for jobs using a detailed query with an arcade expression
varsearch=newSearchQuery(){// Search for jobs assigned to the current user using the arcade expression '$currentUser'Q="\"assignedType='User' AND closed=0 AND assignedTo='\" + $currentUser + \"' \"",Fields=["jobId","jobName","assignedTo","dueDate"],// Sort by job name in ascending orderSortFields=[newSortField(){FieldName="jobName",SortOrder=SortOrder.Asc}]};varjobManager=WorkflowClientModule.JobsManager;varsearchResults=jobManager.SearchJobs(search);varfields=searchResults.Fields;varresults=searchResults.Results;
Search for jobs using a simple string
varsearch=newSearchQuery(){Search="My Search String"};varjobManager=WorkflowClientModule.JobsManager;varsearchResults=jobManager.SearchJobs(search);varfields=searchResults.Fields;varresults=searchResults.Results;// Use the fields and results collections
Get statistics for jobs
varquery=newJobStatisticsQuery(){// Search for open jobs assigned to usersQ="\"assignedType='User' AND closed=0 \""};varjobManager=WorkflowClientModule.JobsManager;varresults=jobManager.CalculateJobStatistics(query);vartotalJobs=results.Total;
varjobManager=WorkflowClientModule.JobsManager;// Specify specific current steps in a job to runvarstepIds=newList<string>{"step12345","step67890"};jobManager.RunSteps(jobId,stepIds);
Stop running steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Get the job Id associated with the active map viewjobId=jobManager.GetJobId();// Stop the current steps in the job with the given id.jobManager.StopSteps(jobId);
Stop specific running steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Get the job Id associated with the active map viewjobId=jobManager.GetJobId();// Specify specific running steps in a job to stopList<string>stepIds=["step12345","step67890"];jobManager.StopSteps(jobId,stepIds);
Finish steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Finish the current steps in the job with the given id.jobManager.FinishSteps(jobId);
// Subscribe to the job message event to start receiving job and step notifications.// Use the subscription token to unsubscribe from the event.subscriptionToken=JobMessageEvent.Subscribe(e =>{varjobId=e.Message.JobId;varmsgType=e.MessageType;varmessage=e.Message;// Include logic to process the job / step messages});// Subscribe to certain jobs. This will add these jobIds to the list of already subscribed jobs.varnotifManager=WorkflowClientModule.NotificationManager;notifManager.SubscribeToJobs(jobIds);
Unsubscribe to messages for the given jobs
// Unsubscribe from the job message event using the subscription tokenJobMessageEvent.Unsubscribe(subscriptionToken);// Unsubscribe from jobs using the same instance of Notification Manager used to subscribe to jobs.// This will remove the jobs from the subscribed job list if no other clients are subscribed to those jobs.varnotifManager=WorkflowClientModule.NotificationManager;notifManager.UnsubscribeFromJobs(jobIds);
Send a response to Workflow Manager Server pertaining to a job's current step
// Send a step response to Workflow Manager Server with additional information required for the step to continue.// In this example, provide an answer response to a QuestionStepInfoRequiredMessage so that the Question step can complete.// The response must include the jobId, stepId, and other information pertinent to the step.varstepInfoResponseMessage=newQuestionStepInfoResponseMessage(){JobId=jobId,StepId=stepId,QuestionResponse=1,Comment="Selected question response option 1"};varstepResponse=newStepResponse(){Message=stepInfoResponseMessage};varnotifManager=WorkflowClientModule.NotificationManager;notifManager.SendStepResponse(stepResponse);