If you want to simplify your workflows and improve their speed, you can use code to add dynamic activities to your workflows at run time. This topic demonstrates how to create two forms and a workflow, add one form to the workflow dynamically, add the other form statically, and pass values from the dynamic form to the static one in code.
We will add this form activity to the workflow dynamically.
A blank form appears. On the tool ribbon, click Add Object.
|
Here, we essentially create the same form as above, but this time with read-only fields.
Save, then Compile and Publish the form, this time restarting your Web Role Service and restarting Workflow Studio.
It is important to restart Workflow Studio at this point. Until you do so, the forms are not available for use in workflows. |
In this workflow, we use a system code activity to add an instance of the dynamic form, and add a reference to the form so that the workflow has access to its properties.
In the Save Workflow dialog that appears, the Package is populated with the one you selected; fill in the Name, Workflow Title, and Description fields as appropriate, and click OK.
A blank workflow with only FlowStart and FlowStop endpoints appears on the Workflow Designer tab.
Add code like the following to the event handler, where MyDynamicFormActivity is the full name of the class we created.
// Add an instance of the dynamic form to this activity. MyDynamicFormActivity dynamicForm = new MyDynamicFormActivity(); this.MyDynamicActivity.AddDynamicActivity(dynamicForm); |
With the System Code Activity selected (DynamicActivity in this example), in the Properties tab under Dynamic Activity, type a name for your event handler in the DynamicCreated property. In this example, we use OnDynamicFormCreate.
Press Enter and the code editor appears below the workflow.
If you want to open the code editor for the event handler later, click the Solution tab and expand the Event Handlers node, then double-click the event handler. |
Add code like the following to pre-populate the form with values.
// Get a known dynamic activity. MyDynamicFormActivity dynamicForm = e.GetActivity<MyDynamicFormActivity>(); // Another way to get the dynamic activity. MyDynamicFormActivity dynamicForm2 = e.Activity as MyDynamicFormActivity; // Pre-fill the form with values. dynamicForm.FirstName = "Enter your first name here"; dynamicForm.EmailAddress = "enteryour@email.com"; |
To close the code editor, click the Close Editor button in the toolbar to the right. |
Add code like the following to pass the values from the dynamic form to the static form.
// Get a known dynamic activity. MyDynamicFormActivity dynamicForm = e.GetActivity<MyDynamicFormActivity>(); // Another way to get the dynamic activity. MyDynamicFormActivity dynamicForm2 = e.Activity as MyDynamicFormActivity; // Assign values from the dynamic form to the static form. this.myStaticFormActivity1.FirstName = dynamicForm.FirstName; this.myStaticFormActivity1.EmailAddress = dynamicForm.EmailAddress; |
Users do not have direct access to workflows. Instead, Workflow Studio creates a request workflow that they can interact with that runs the actual workflow.
https://sso.empoweriam.com/ui#w#/MyDynamicActivityWorkflow
|
|