13. Set the Current User's Details on the Request Form
In this step you will edit the Leave Request Workflow (Default) state's "form initializing" rule, and add an action to load the current user's previous leave requests into the Leave Request List View. Transfer the current user's system values (Email and Display Name) to the Leave Request Item View. K2 keeps track of the current user's system details such as their display name, email, department and manager as system values. You will use two of these system values to personalize the Leave Request Form. When you launch the form, K2 will displays your name and email automatically.
-
First, you will add an action to retrieve the current user's previous leave requests. You will populate the Leave Request List View these records as the form loads. Edit the form initializing rule for the Leave Request Workflow (Default) state on the Leave Request Form. Add an Execute a View method action for the Leave Request List View, Get List method.
- Begin by editing the rule that runs when the form first loads, or initializes, for the leave requester. With the Leave Request Worfklow (Default) state still highlighted, edit the When the Form is Initializing rule.
- Confirm the Actions tab is active, then click Execute a View method to add it to the rule definition pane.
- Click the select View link and select Leave Request List View. This is the view that displays the previous leave requests at the bottom of the form.
- Click the select method link and select Get List. The Get List method does just that, retrieves records from a SmartObject. But you do not want ALL records returned, so you will configure the action to filter the records by the employee's email.
- Begin by editing the rule that runs when the form first loads, or initializes, for the leave requester. With the Leave Request Worfklow (Default) state still highlighted, edit the When the Form is Initializing rule.
-
Map the system value (current user) email to the Employee Email input property.
- Now you need to tell K2 which SmartObject records you want returned. You want the current user's records. You will set up a filter so that K2 only returns the current user's leave requests. For this tutorial, you will use the email as the filter, since email addresses are unique. This step also highlights why the Employee Email a data label and not an editable text box. The user cannot change a data label. The data label value is the user's system email value so it will remain consistent throughout all the records.
Click the (configure) link. On the Input Mappings screen, expand the Context Browser > System Values > Current User nodes, then drag the Email property into the Employee Email field. The input mapping value is the filter K2 uses when returning records.
- Now you need to tell K2 which SmartObject records you want returned. You want the current user's records. You will set up a filter so that K2 only returns the current user's leave requests. For this tutorial, you will use the email as the filter, since email addresses are unique. This step also highlights why the Employee Email a data label and not an editable text box. The user cannot change a data label. The data label value is the user's system email value so it will remain consistent throughout all the records.
-
Map the return properties to the Leave Request List View output mappings.
- Now you will map the return properties K2 will take the filtered records it finds and populate the list view with the SmartObject records..
Click the Output Mappings button. Drag the Return Properties into the Leave Request List View fields. These are the properties that become the list view values. You may have to collapse the item view to see the list view in the Mapping Destinations pane. Click FINISH.
When you created the list view, you selected the columns you wanted to include. The Display Row fields below are those columns. You are mapping the SmartObject properties to their corresponding list view columns.
- Now you will map the return properties K2 will take the filtered records it finds and populate the list view with the SmartObject records..
- Add a transfer data action. Map the system current user display name and email to the appropriate item view controls.
- Now you will map the current user's name and email to the form so that the values load when the form loads. This is not required, but is a nice feature for your users. It also forces the leave request records to match system values. In this case, you need a consistent email address for the leave requester. As you become more familiar with rules, you can search for keywords to locate the event, condition or action you need. This eliminates having to scroll through the rule options.
With the Actions tab still active, search the keyword
transfer
then click on Transfer data to add it to the rule definition pane. - Click (configure). Expand the Context Browser > System Values > Current User nodes. Drag the Display Name into the Employee Name Text Box field. Drag the Email into the Employee Email Data Label field. Click OK.
- The completed When the Form is Initializing rule should look like the image below. Click OK to exit the Rule Designer. Keep the form open, as you will work with rules in the next section.
- Now you will map the current user's name and email to the form so that the values load when the form loads. This is not required, but is a nice feature for your users. It also forces the leave request records to match system values. In this case, you need a consistent email address for the leave requester. As you become more familiar with rules, you can search for keywords to locate the event, condition or action you need. This eliminates having to scroll through the rule options.
Review
In this step, you edited the form initializing rule and added two actions. The first action retrieves the current user's leave requests, then populates the list view with the records found. You used the requester's email to filter the SmartObject records. The second action retrieves the current user's system value display name and email. When the requester launches the Leave Request Form, the name and email fields is pre-populated. In the next step, you will work with the state the approving manager sees. This time, you will populate the form with the leave requester's previous leave requests.