22. Edit the Expense Claim Form (Originator Rework State)
In this step, you edit the third state, Originator Rework State. This is the form's configuration and behavior the originator experiences as they edit and resubmit (or cancel) their claim. In this state, you want the fields editable, so the originator can change values to rework the claim. You will make the approver and finance comments read-only as the originator shouldn't change these fields.
The remaining rules save changes made to the header and details content. You will update the header and details SmartObjects with any changes to existing fields, then create new details records if the originator adds any new line items. Finally, you will delete any details records the originator removes from the line items.
- Edit the form initializing rule for the Originator Rework State. You will make the approval and finance comments fields read-only, then hide the Submit Button Table. You will finish this rule with actions to load the originator's content into the header and details views. Use the table below as a guide. If a setting is not specified, assume the default value. If you need help, expand the "Show me how..." section.
Rule Configure Notes Rule
(Edit) When the Form is Initializing
Condition
(None)
Action
(New) Specify edit state for View and Form controlsRead-only controls: - Approval Date
- Approver Comments Text Area
- Finance Process Date
- Finance Processor Comments Text Area
The originator should not use the approver or finance comments fields, so you will make these controls read-only. ( Action
(New) Hide a Form controlSelect control:
Submit Button TableThe originator uses the Workflow Task view to select their decision and submit their response. The submit and cancel buttons are not in use for this state, so you will hide them to avoid any confusion. Action
(New) Execute a View methodLoad originator's header view content: - (View) Expense Claim Header View
- (Method) Load
- (configure) Map the Expense Claim Header View > Expense Claim Header SmartObject > ID to the Input Properties > ID
You want to load the originator's header content into the header view so that the originator can edit their claim. Here, you are mapping the SmartObject ID for the current record over to the header view. K2 loads the current record into the header view using the record ID. Action
(New) Execute a View methodLoad originator's details view content: - (View) Expense Claim Details View
- (Method) Get List
- (configure) Map the Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID
You want to load the originator's details content into the details view so that they can edit their claim line items. Here, you are mapping the SmartObject ID for the current header record over to the details view. The Expense Claim ID is the common field between the header record and the details records. K2 loads the details records that match the header record ID. - Edit the Originator Rework State, When the Form is Initializing rule.
- First, you will make the approver and finance comments read-only, since the originator should not use these fields. With the Actions tab active, search for
edit state
then click Specify edit state for View and Form controls to add it to the rule definition pane. Click (configure). - On the Specify edit state for View and Form controls screen, make the Approval Date, Approver Comments Text Area, Finance Process Date and Finance Processor Comments Text Area controls READ-ONLY for the Expense Claim Header View. Click OK to save your changes.
- Next, you will hide the Submit Button Table so that the originator does not see the submit and cancel buttons. The originator uses the submit button on the view that K2 adds with the actions (such as Resubmit Claim or Cancel Claim). The original submit and cancel buttons may be confusing, so you will hide them for the rework state. With the Actions tab still active, search for
hide
then click the Hide a Form control action to add it to the rule definition pane. Click the select control link and select Submit Button Table. - The last two actions load the originator's content into the header and details views. With the Actions tab still active, delete the search keyword so that K2 loads the default actions. Click Execute a View method to add it to the rule definition pane. Click the select View link and select Expense Claim Header View. Click the select method link and select Load. Click (configure).
- From the Context Browser, map the Expense Claim Form > Expense Claim Header View > Expense Claim Header SmartObject > ID to the Input Properties > ID. Click FINISH to save and exit this setting.
- Now, you will add the action to retrieve the details records. Click Execute a View method once again to add a second instance of this action to the rule definition pane. Click the select View link and select Expense Claim Details View. Click the select method link and select Get List. Click (configure).
- From the Context Browser, map the Expense Claim Form > Expense Claim Header View > Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID. Click FINISH to save and exit this setting. Here, you are mapping the ID from the header SmartObject to a property in the details SmartObject. K2 returns all details records that match the header record ID.
- The form initializing rule should look like the image below. Click OK to save and exit this rule.
-
Now, you are going to work with rules to process any changes made to fields in both the header and details views. You want to save changes made to the header view, then save changes made to existing line items in the details view. Then you want to create new details records for any line items added and finally, you want to delete any details records for any line items removed. Use the table below as a guide. If a setting is not specified, assume the default value. If you need help, expand the "Show me how..." section.
Rule Configure Notes Rule
(Edit) Workflow view is being submitted
Condition
(None)
Action
(New) Execute a View methodSave changed header content back to the Expense Claim Header SmartObject: - (View) Expense Claim Header View
- (Method) Save
- (configure) Auto-map the Input Properties. Replace the auto-mapped ID property with the Expense Claim Header View > Expense Claim Header SmartObject > ID. Do not skip this step or K2 will not update the existing SmartObject record!
During the rework phase of the application, the originator may make changes to fields in the header view and the details view. Here, you are saving any changes made to the header fields back to the Expense Claim Header SmartObject. You can auto-map the properties, however, you must replace the auto-mapped ID property with the Expense Claim Header SmartObject > ID property so K2 knows which existing record to update. Action
(New) Execute a View method for items that are in a specific stateSave changed details content back to the Expense Claim Details SmartObject: - (View) Expense Claim Details View
- (Method) Save
- (Select item state) Changed
- (configure) Map the Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID. Map the remaining properties from the Expense Claim Details SmartObject to the remaining Input Properties.
You want to update any existing line items with changes from the originator. Note that "save" is the equivalent to "update" in K2 terms. Action
(New) Execute a View method for items that are in a specific stateSave new details content back to the Expense Claim Details SmartObject: - (View) Expense Claim Details View
- (Method) Create
- (Select item state) Added
- (configure) Map the Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID. Map the remaining properties from Expense Claim Details SmartObject to the remaining Input Properties.
Here, you are mapping any new line items added to the details view back to the Expense Claim Details SmartObject. Once again, you will map the "header" ID to the "details" Expense Claim ID property to bind the details records with their header record. Action
(New) Execute a View method for items that are in a specific stateRemove deleted line items from the Expense Claim Details SmartObject: - (View) Expense Claim Details View
- (Method) Delete
- (Select item state) Removed
- (configure) Map the Expense Claim Details SmartObject > ID to the Input Properties > ID.
You will remove any line item records the originator deleted during the rework process. Batch Processing Change the processing order of the create, save, and delete actions so that they run in a batch. When actions run as a batch, K2 processes them as a group before moving on to the next rule, condition, or action. Completed Originator Rework State Actions - When the Workflow View is being submitted - Edit the When the Workflow View is being submitted rule for the Originator Rework State. This is the rule that fires when the originator submits their changes.
- First, you will save any changes made to the header view. With the Actions tab active, click Execute a View method to add it to the rule definition pane. Select the Expense Claim Header View and the Save method. Remember, save is the same as "update" in K2 terms. You are updating the SmartObject record. Click (configure).
- Click Auto Map. You will let K2 map the input properties to their SmartObject properties. There is one change you must make, however. You must delete the auto-mapped ID and replace it with the Expense Claim Header SmartObject > ID so that K2 knows which record to update. Do not skip this step or K2 will not update the existing SmartObject record! Delete the ID property created by the auto-map. Drag the Expense Claim Form > Expense Claim Header View > Expense Claim Header SmartObject > ID into the Input Properties > ID field. Click FINISH to save and exit this setting.
- Now, you will save any changes made to existing line items in the details view. Click Execute a View method for items that are in a specific state to add it to the rule definition pane. For the view, select Expense Claim Details View. For the method, select Save. For the item state, select Changed. You are saving any line items that changed back to the details SmartObject. Click (configure).
- First, map the header ID to the Expense Claim ID input property. Then, map the remaining details properties. Map the Expense Claim Form > Expense Claim Header View > Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID. Map the remaining input properties from the Expense Claim Details View > Expense Claim Details SmartObject > (remaining properties). Note that you are mapping SmartObject properties to the Input Properties and not controls. This is standard for looping through list values. Click FINISH to save and exit this setting.
- Now, that you have saved changed content from the header and details views, you will save new content from the details view. Click Execute a View method for items that are in a specific state to add it to the rule definition pane. Select the Expense Claim Details View, the Create method, and the Added item state. You are creating a new details record for each new line item added in the details view. Click (configure).
- Once again, map the Expense Claim Form > Expense Claim Header View > Expense Claim Header SmartObject > ID to the Input Properties > Expense Claim ID field. Map the remaining input properties from the Expense Claim Details View > Expense Claim Details SmartObject. Click FINISH to save and exit the settings.
- The last action deletes any SmartObject details records that the originator removed from the details view. Click Execute a View method for items that are in a specific state to add it to the rule definition pane. Select the Expense Claim Details View, the Delete method, and the Removed item state. Click (configure).
- Drag the Expense Claim Form > Expense Claim Details View > Expense Claim Details SmartObject > ID to the Input Properties > ID field. At runtime, K2 will loop through the details view and remove any existing SmartObject details records that the user removed form the details view. Click FINISH.
- The last edit to this rule is to change the processing order for the actions you just added. You want them to run as a batch where K2 processes the actions as a group before moving on to the next rule, condition, or action. Locate the action for the Save method - Expense Claim Header View. Click then and change it to also. Repeat this for the Save method - Expense Claim Details View, Create method - Expense Claim Details View, and finally, the Delete method - Expense Claim Details View.
- Your actions should look like the image below. Click OK to save and exit the Rule Designer.
Review
In this step, you configured the Originator Rework State's rules. You disabled the approver and finance comments controls so that the originator doesn't enter anything in them. You hid the original submit and cancel buttons. The bulk of this topic covered saving changes made by the originator back to the header and details SmartObjects. You learned how to use the "items in a specific state" action that loops through editable lists for processing. In the next step, you will work with the final state, Finance Processing State.