We know that users can define data fields or variables at package or process level in an XPDL file and then this XPDL file is uploaded to Aspose.Workflow engine for managing the workflow. Aspose.Workflow allows its users to Read or Update these Data Fields/Variables at runtime using its simple API.
Reading Data Fields/Variables
Developers can read all kinds of data fields/variables (either defined at package or process level) being used by a process instance using the Variables property of IProcessInstance interface. Please follow the steps below to do so but after logging on to the Aspose.Workflow engine:
- Create a reference of IInstanceAdmin interface using InstanceAdmin property of IEngine object
- Retrieve a process instance whose variables need to be accessed. In our case, we use GetProcessInstance method of IInstanceAdmin object that returns the IProcessInstance object encapsulating the specified process instance after taking its ID as a parameter
- Use the Variables property of IProcessInstance object to retrieve the list of all data fields or variables as an IDictionary object
An example is given below to demonstrate about accessing data fields or variables.
Example:
[C#]
//Instantiate an object of EngineManager
EngineManager manager = EngineManager.Instance;
//Configure the EngineManager object
manager.Configure();
//Create an object of IEngine interface
IEngine engine = manager.Engine;
//Login to the Aspose.Workflow engine
engine.Login("aspose","aspose");
//Create an instance of IInstanceAdmin interface
IInstanceAdmin instanceAdmin = engine.InstanceAdmin;
//Accessing a process instance using its instance ID
IProcessInstance instance = instanceAdmin.GetProcessInstance("instanceId");
//Retrieving a list of all data fields or variables
IDictionary variables = instance.Variables
[VB.NET]
'Instantiate an object of EngineManager
Dim manager As EngineManager = EngineManager.Instance
'Configure the EngineManager object
manager.Configure()
'Create an object of IEngine interface
Dim engine As IEngine = manager.Engine
'Login to the Aspose.Workflow engine
engine.Login("aspose","aspose")
'Create an instance of IInstanceAdmin interface
Dim instanceAdmin As IInstanceAdmin = engine.InstanceAdmin
'Accessing a process instance using its instance ID
Dim instance As IProcessInstance = instanceAdmin.GetProcessInstance("instanceId")
'Retrieving a list of all data fields or variables
IDictionary variables = instance.Variables
Updating Data Fields/Variables
We have learned so far that how can we read data fields or variables but what if a user want to update the values of these data fields at runtime?
Well, Aspose.Workflow facilitates its users to cope with this issue too. In our above discussion, we discussed that users can read all data fields being used in a process instance with the help of Variables property of IProcessInstance interface. Variables property returns a list of all data fields of a particular process instance in the form of an IDictionary object.
So, to update the values of these data fields, we will create an object of IDictionary interface by typecasting an instance of Hashtable. Then we can add the updated values of data fields in Key/Value pair format to the IDictionary object.
After storing the updated values of data fields in the IDictionary object, we can pass this IDictionary object to the CompleteTask method of IWorklist interface. For more information about creating an object of IWorklist interface, please Click here . CompleteTask method will also take the task ID of a specific task, which will use these updated values of data fields.
Before calling CompleteTask method, the task should be accepted by the current user that wants to complete the task. So, to make the task accepted by the current user, developers should call AcceptTask method of IWorklist interface. AcceptTask method will take the task ID as a parameter and will make that task accepted by the current user.
An example is given below to update the values of data fields before completing a task.
Example:
[C#]
//Setting the task ID
string taskId = "1_1_TestInstance_TestInstance_Wor1";
//Creating an IDictionary object containing the updated values of data fields
//where "TestVar_1" and "TestVar_2" are names of the data fields
IDictionary valueMappings = new Hashtable();
valueMappings["TestVar_1"] = "50";
valueMappings["TestVar_2"] = "25";
//Instantiate an object of EngineManager
EngineManager manager = EngineManager.Instance;
//Configure the EngineManager object
manager.Configure();
//Create an object of IEngine interface
IEngine engine = manager.Engine;
//Login to the Aspose.Workflow engine
engine.Login("aspose","aspose");
//Accept the task before completing it
engine.Worklist.AcceptTask(taskId);
//Complete the task with updated values of data fields
engine.Worklist.CompleteTask(taskId,valueMappings);
[VB.NET]
'Setting the task ID
Dim taskId As String = "1_1_TestInstance_TestInstance_Wor1"
'Creating an IDictionary object containing the updated values of data fields
'where "TestVar_1" and "TestVar_2" are names of the data fields
Dim valueMappings As IDictionary = New Hashtable()
valueMappings("TestVar_1") = "50"
valueMappings("TestVar_2") = "25"
'Instantiate an object of EngineManager
Dim manager As EngineManager = EngineManager.Instance
'Configure the EngineManager object
manager.Configure()
'Create an object of IEngine interface
Dim engine As IEngine = manager.Engine
'Login to the Aspose.Workflow engine
engine.Login("aspose","aspose")
'Accept the task before completing it
engine.Worklist.AcceptTask(taskId)
'Complete the task with updated values of data fields
engine.Worklist.CompleteTask(taskId,valueMappings)Describes how to start using Aspose.Workflow engine.
12/28/2005 6:20:26 AM - -210.56.19.84