-
Notifications
You must be signed in to change notification settings - Fork 121
ProSnippets WorkflowManager
UmaHarano edited this page May 13, 2026
·
9 revisions
Language: C#
Subject: Prosnippets WorkflowManager
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: Esri, http://www.esri.com
Date: 4/30/2026
ArcGIS Pro: 3.7
Visual Studio: 2026
// determine if there is an active Workflow Manager connection
var isConnected = WorkflowClientModule.IsConnected;
// Use the value of isConnected to determine if you can proceed with Workflow Manager operations// Get the Workflow Manager item Id
var itemId = WorkflowClientModule.ItemId;
// Use the itemId to identify the Workflow Manager item// Get the Workflow Manager server url
var serverUrl = WorkflowClientModule.ServerUrl;
// Use the serverUrl to identify the Workflow Manager server// Get the job Id associated with the active map view
var jobManager = 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
var jobManager = 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 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
Func<object[], Task> overrideFunction = (args) => QueuedTask.Run(() =>
{
try
{
// Get the jobId property from the OpenProProjectItemsStep arguments and store it.
OpenProProjectItemsStepCommandArgs stepArgs = (OpenProProjectItemsStepCommandArgs)args[0];
var jobId = 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 ExecuteCommandArgs
IPlugInWrapper wrapper = FrameworkApplication.GetPlugInWrapper(id);
if (wrapper is ICommand command && command.CanExecute(null))
command.Execute(null);
}
catch (Exception e)
{
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// Note: QueuedTask is required to call Workflow Manager API methods
// GetJob returns an existing job
try
{
var jobManager = WorkflowClientModule.JobsManager;
var job = 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 objectvar search = new SearchQuery()
{
// Search for all open high priority jobs assigned to users
Q = "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 order
SortFields =
[
new SortField() { FieldName = "assignedTo", SortOrder = SortOrder.Asc },
new SortField() { FieldName = "dueDate", SortOrder = SortOrder.Desc }
]
};
var jobManager = WorkflowClientModule.JobsManager;
var searchResults = jobManager.SearchJobs(search);
var fields = searchResults.Fields;
var results = searchResults.Results;var search = new SearchQuery()
{
// 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 order
SortFields = [new SortField() { FieldName = "jobName", SortOrder = SortOrder.Asc }]
};
var jobManager = WorkflowClientModule.JobsManager;
var searchResults = jobManager.SearchJobs(search);
var fields = searchResults.Fields;
var results = searchResults.Results;var search = new SearchQuery() { Search = "My Search String" };
var jobManager = WorkflowClientModule.JobsManager;
var searchResults = jobManager.SearchJobs(search);
var fields = searchResults.Fields;
var results = searchResults.Results;
// Use the fields and results collectionsvar query = new JobStatisticsQuery()
{
// Search for open jobs assigned to users
Q = "\"assignedType='User' AND closed=0 \""
};
var jobManager = WorkflowClientModule.JobsManager;
var results = jobManager.CalculateJobStatistics(query);
var totalJobs = results.Total;var jobManager = WorkflowClientModule.JobsManager;
jobManager.RunSteps(jobId);var jobManager = WorkflowClientModule.JobsManager;
// Specify specific current steps in a job to run
var stepIds = new List<string> { "step12345", "step67890" };
jobManager.RunSteps(jobId, stepIds);var jobManager = WorkflowClientModule.JobsManager;
// Get the job Id associated with the active map view
jobId = jobManager.GetJobId();
// Stop the current steps in the job with the given id.
jobManager.StopSteps(jobId);var jobManager = WorkflowClientModule.JobsManager;
// Get the job Id associated with the active map view
jobId = jobManager.GetJobId();
// Specify specific running steps in a job to stop
List<string> stepIds = ["step12345", "step67890"];
jobManager.StopSteps(jobId, stepIds);var jobManager = WorkflowClientModule.JobsManager;
// Finish the current steps in the job with the given id.
jobManager.FinishSteps(jobId);var jobManager = WorkflowClientModule.JobsManager;
List<string> stepIds = ["step12345", "step67890"];
jobManager.FinishSteps(jobId, stepIds);subscriptionToken = WorkflowConnectionChangedEvent.Subscribe(e =>
{
// The connection has changed
// Do something relevant
return Task.CompletedTask;
});WorkflowConnectionChangedEvent.Unsubscribe(subscriptionToken);// 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 =>
{
var jobId = e.Message.JobId;
var msgType = e.MessageType;
var message = 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.
var notifManager = WorkflowClientModule.NotificationManager;
notifManager.SubscribeToJobs(jobIds);// Unsubscribe from the job message event using the subscription token
JobMessageEvent.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.
var notifManager = WorkflowClientModule.NotificationManager;
notifManager.UnsubscribeFromJobs(jobIds);// 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.
var stepInfoResponseMessage = new QuestionStepInfoResponseMessage()
{
JobId = jobId,
StepId = stepId,
QuestionResponse = 1,
Comment = "Selected question response option 1"
};
var stepResponse = new StepResponse()
{
Message = stepInfoResponseMessage
};
var notifManager = WorkflowClientModule.NotificationManager;
notifManager.SendStepResponse(stepResponse);
Home | API Reference | Requirements | Download | Samples | Snippets
-
Determine if there is an active Workflow Manager connection
-
Get the Workflow Manager item Id
-
Get the Workflow Manager server url
-
Get the job Id associated with the active map view
-
Get the job Id associated with a map
-
Get the job Id associated with a running OpenProProjectItems step
-
Get a job
-
Search for jobs using a detailed query
-
Search for jobs using a detailed query with an arcade expression
-
Search for jobs using a simple string
-
Get statistics for jobs
-
Run steps on a job
-
Run specific steps on a job
-
Stop running steps on a job
-
Stop specific running steps on a job
-
Finish steps on a job
-
Finish specific steps on a job
-
Subscribe to a workflow connection changed event.
-
Unsubscribe from a workflow connection changed event.
-
Subscribe to job notification messages
-
Unsubscribe to messages for the given jobs
-
Send a response to Workflow Manager Server pertaining to a job's current step