In Workflow Studio, we use binding to pass data from one activity to another or even to flow data from the workflow itself to any of the activities. Binding can be achieved in two ways: one way is to use the Binding Mapper, and the other
...
is by writing custom C# code in the activities.
Bindings allow you to drag and drop properties from one activity to another using a built-in property mapper or binding mapper. Bindings are bi-directional.
In order to demonstrate how binding works I will create a Workflow and will put one Lookup control and one Form on it. My lookup control will display the list of people in EmpowerID and based on the selected record from the lookup control I will pass that user information on to my Form and my Form will display the selected user information.
Our focus during this demonstration will be on understanding how Binding works in Workflow Studio, rather than delving into the creation of Forms and Lookup Controls. If you're interested in learning about the creation of lookup controls, please refer to the previous topic. Similarly, if you're keen on exploring Forms, you can proceed to our upcoming topic dedicated to Forms.
Let's consider a Workflow where we incorporate a single-select lookup control, allowing the selection of only one record at a time. Additionally, there is a form within the workflow, featuring several common fields. Below, you'll find images showing how the lookup control and form appear in both Workflow Studio and EmpowerID Web UI for your reference.
Now let's see how these two components are placed within a Workflow and what they look like. Please refer to the image below
Now that we have our workflow ready, featuring a Lookup Control and a Form Control placed within it, it's time to pass the selected user's data from the lookup control to our Form. To accomplish this, let's navigate to the Bindings tab. Here, you'll encounter two identical columns. On the left-hand side, expand the tree control for our lookup. Then, further expand its Output node and select the SelectedValueAsComponent property. Next, drag and drop it onto the right-hand side column. As you expand the tree control for the Form on the right-hand side, delve into its Input/Output node. There, drop your SelectedValueAsComponent Propertyonto the TargetPerson (this is the custom name assigned to our Person Rbac component on our Form; you could have chosen any name here)
Now, it's time to test the workflow. Run the workflow, select a user, click the Next button, and observe how the user information gets passed on to the form. You can refer to the two screenshots provided below.
It worked Successfully!
Let's now attempt to achieve the same outcome by writing custom C# code. To begin, navigate to the binding tab of your Workflow. Remove the existing bindings and proceed to publish the workflow and verify that binding is not working anymore.
Now right click on your Form placed on the Workflow and click again on the Edit Get/Set Data Logic it will create a class for you with SetDataCode and GetDataCode methods.
In the SetDataCode method write below code
CurrentWorkflow.YOURFORMNAME.YOURFORMDATANAME = CurrentWorkflow.YOURLOOKUPNAME.SelectedValueAsComponent
Code Block |
---|
CurrentWorkflow.course_PersonFormActivity1.TargetPerson = CurrentWorkflow.course_PersonLKActivity1.SelectedValueAsComponent; |
Publish your workflow both from Workflow Studio and in the EmpowerID Web UI.
Run your workflow, and you'll find that it functions in the same manner as it did before when we did the binding using the Binding Mapper or by going to the Bindings tab.