How to determine if there is an active Workflow Manager connection
// determine if there is an active Workflow Manager connectionvarisConnected=WorkflowClientModule.IsConnected;
How to get the Workflow Manager item Id
// Get the Workflow Manager item IdvaritemId=WorkflowClientModule.ItemId;
How to get the Workflow Manager server url
// Get the Workflow Manager server urlvarserverUrl=WorkflowClientModule.ServerUrl;
How to get the job Id associated with the active map view
// Get the job Id associated with the active map viewvarjobManager=WorkflowClientModule.JobsManager;varjobId=jobManager.GetJobId();
How to get the job Id associated with a map
// Get the job Id associated with a mapmapUri="myMapUri";// Get a reference to a map using the ArcGIS.Desktop.Mapping API (active view, project item, etc.)varjobManager=WorkflowClientModule.JobsManager;varjobId=jobManager.GetJobId(mapUri);
How to 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 example//protected override Func<Object[], Task> ExecuteCommandArgs(string id)//{// return func1;//}Func<Object[],Task>func1=(object[]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);varcommand=wrapperasICommand;if(command!=null&&command.CanExecute(null))command.Execute(null);}catch(System.Exceptione){ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"ERROR: {e}","Error running command");}});
How to get a job
// 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}
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=newList<string>{"jobId","jobName","assignedTo","dueDate"},// Sort by job assignment in ascending order and due date in descending orderSortFields=newList<SortField>{newSortField(){FieldName="assignedTo",SortOrder=ArcGIS.Desktop.Workflow.Client.Models.SortOrder.Asc},newSortField(){FieldName="dueDate",SortOrder=ArcGIS.Desktop.Workflow.Client.Models.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=newList<string>{"jobId","jobName","assignedTo","dueDate"},// Sort by job name in ascending orderSortFields=newList<SortField>{newSortField(){FieldName="jobName",SortOrder=ArcGIS.Desktop.Workflow.Client.Models.SortOrder.Asc}}};varjobManager=WorkflowClientModule.JobsManager;varsearchResults=jobManager.SearchJobs(search);varfields=searchResults.Fields;varresults=searchResults.Results;
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 runstepIds=newList<string>{"step12345","step67890"};jobManager.RunSteps(jobId,stepIds);
How to stop running steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Get the job Id associated with the active map viewvarjobId=jobManager.GetJobId();// Stop the current steps in the job with the given id.jobManager.StopSteps(jobId);
How to stop specific running steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Get the job Id associated with the active map viewvarjobId=jobManager.GetJobId();// Specify specific running steps in a job to stopstepIds=newList<string>{"step12345","step67890"};jobManager.StopSteps(jobId,stepIds);
How to finish steps on a job
varjobManager=WorkflowClientModule.JobsManager;// Finish the current steps in the job with the given id.jobManager.FinishSteps(jobId);
How to subscribe to a workflow connection changed event.
varsubscriptionToken=WorkflowConnectionChangedEvent.Subscribe(e =>{// The connection has changed - Get the user's sign in statusvarisUserSignedIn=e.IsSignedIn;returnTask.CompletedTask;});
How to unsubscribe from a workflow connection changed event.