ProConcepts Workflow Manager Classic - Esri/arcgis-pro-sdk GitHub Wiki

The ArcGIS.Desktop.Workflow namespace provides access to classes and members that allow you to:

  • Establish and manage a Workflow Manager database connection
  • Create jobs and configure their properties
  • Execute job workflows and queries
  • Retrieve configuration information from the Workflow Manager database

ArcGIS.Desktop.Workflow.dll

Language:      C#
Subject:       Workflow Manager
Contributor:   ArcGIS Pro SDK Team <[email protected]>
Organization:  Esri, http://www.esri.com
Date:          10/06/2024
ArcGIS Pro:    3.4
Visual Studio: 2022

In this topic

Workflow connection

A workflow connection provides access to the jobs and configuration elements within a Workflow Manager enterprise geodatabase.

A prerequisite to using the Workflow Manager ArcGIS Pro SDK is that the workflow connection must be set up in the project in advance. For more information on how to configure a workflow connection, see Workflow connection.

An ArcGIS Pro project only supports one workflow connection at a time, so the active workflow connection can be accessed directly using the ConnectAsync method from the WorkflowModule class.

// Get JobsManager and ConfigurationManager for the project
var connection = await QueuedTask.Run(() => WorkflowModule.ConnectAsync());
var jobsManager = connection.GetManager<ArcGIS.Desktop.Workflow.Models.JobsManager>();
var configManager = connection.GetManager<ArcGIS.Desktop.Workflow.Models.ConfigurationManager>();

Jobs Manager

The Jobs Manager class provides access to the jobs within Workflow Manager. A Job is an object representing a single unit of work that is carried out within an organization. A job is created using the CreateNewJob method, which uses a template known as a job type to configure a job with the desired properties and components (such as the Workflow and Maps).

// Create a job
await QueuedTask.Run(async () =>
{
  // Connect to the workflow connection.  The workflow connection provides connection status information and 
  // allows interaction with the Workflow Manager system through managers.
  WorkflowConnection connection = await WorkflowModule.ConnectAsync();

  // Access configuration and job information
  var configMgr = connection.GetManager<ArcGIS.Desktop.Workflow.Models.ConfigurationManager>();
  var jobType = configMgr.GetVisibleJobTypes().FirstOrDefault();

  JobsManager jobsMgr = connection.GetManager<JobsManager>();
  var jobID =  jobsMgr.CreateNewJob(jobType.ID);
  var job = jobsMgr.GetJob(jobID);
});

The primary identifier of a job is its unique ID, and it is the primary input parameter for methods within the Jobs Manager class such as GetJob and CloseJobs.

If the desired job's ID is unknown, you can use job queries to find it in the Workflow Manager database.

Queries

Queries are SQL statements that filter the Workflow Manager jobs based on predefined criteria such as who the job is assigned to or the priority of the job. Queries can be executed by using their name or their ID from the Jobs Manager class within the methods ExecuteQuery and ExecuteQueryXML.

// Execute "All Jobs" Query 
await QueuedTask.Run(async () =>
{
  // Connect to the workflow connection.  The workflow connection provides connection status information and 
  // allows interaction with the Workflow Manager system through managers.
  WorkflowConnection connection = await WorkflowModule.ConnectAsync();

  // Access configuration and job information
  JobsManager jobsMgr = connection.GetManager<JobsManager>();
  var queryResultReturn = jobsMgr.ExecuteQuery("All Jobs");
});

Configuration Manager

The Configuration Manager class provides access to many configuration elements that are defined within the Workflow Manager database such as users, groups, and data workspaces. All of these elements are read-only from the database.

To obtain details on a specific user, you can use the GetUser method. To obtain a list of job types that the current user can access for job creation, use GetVisibleJobTypes.

// Get the job types that are visible to the current user 
await QueuedTask.Run(async () =>
{
  // Connect to the workflow connection.  The workflow connection provides connection status information and 
  // allows interaction with the Workflow Manager system through managers.
  WorkflowConnection connection = await WorkflowModule.ConnectAsync();

  // Access configuration and job information
  var configMgr = connection.GetManager<ArcGIS.Desktop.Workflow.Models.ConfigurationManager>();
  var jobsTypes = configMgr.GetVisibleJobTypes();
});

Other methods contained in this class include GetAllUsers, GetAllGroups, GetJobPriorities, GetDataWorkspaces, and GetConfigurationProperty.

Job

The Job class provides access to a Workflow Manager job. A Job may have one or many people working on it. It can be associated with a single dataset, multiple datasets, or no data at all. It is created from a job type, and many of its properties (e.g., assignment) and components (e.g., attachments) can be obtained and set in the Job class. Once a value has been changed for a job, it must be saved using the Save method for the change to be committed to the Workflow Manager database.

For more information on what a job is, see Workflow jobs..

// Get a job and change its description 
await QueuedTask.Run(async () =>
{
  // Connect to the workflow connection.  The workflow connection provides connection status information and 
  // allows interaction with the Workflow Manager system through managers.
  WorkflowConnection connection = await WorkflowModule.ConnectAsync();

  JobsManager jobsMgr = connection.GetManager<JobsManager>();
  var job = jobsMgr.GetJob("512");
  job.Description = "This is a test";
  job.Save();
});

Once a job has been created or obtained and is assigned to the current user it can be executed.

Workflow execution

Workflow execution consists of executing and completing steps in the job. Before executing a step it is important to check whether the step can be executed using the CanExecuteStep method. A step can be executed if the job is assigned to the current user, the job does not have an active hold and the job is not closed. Similarly to complete a step check to see if it can be completed using the CanCompleteStep method.

Use the ExecuteStep and CompleteStep methods to run the workflow. To move to a different step in the workflow use the SetCurrentStep method.

// Execute a step in the workflow
await QueuedTask.Run(async () =>
{
  // Connect to the workflow connection.  The workflow connection provides connection status information and 
  // allows interaction with the Workflow Manager system through managers.
  WorkflowConnection connection = await WorkflowModule.ConnectAsync();

  JobsManager jobsMgr = connection.GetManager<JobsManager>();
  var job = jobsMgr.GetJob(jobID);
  string stepID = job.GetCurrentSteps().First();
  Tuple<bool, string> canExecute = job.CanExecuteStep(stepID);
  if (canExecute.Item1 == true)
    job.ExecuteStep(stepID);
  else
  {
    string errorMsg = canExecute.Item2;
    // do something with the error message
  }
});
⚠️ **GitHub.com Fallback** ⚠️