Applies to:
NITRO activated sites in SharePoint Online, On-premises 2013/2016/2019/SharePoint Server Subscription Edition
Description
Form event actions (FEAs) can be used to add custom functionality on the forms. Please refer this article for more details and examples.
FEAs can be triggered on form load or on a column value change by a user. There are some special scenarios where standard triggers do not work reliably and this article covers one such case.
On form load, logged in user is auto populated in a person and group column and user’s department in a lookup column. Based on this department value, we need to fetch a column value from department list using FEA.
FEA with form load trigger will not work directly in this case as there is some gap in populating user and user’s department after form load. For this we need to write a script to wait until the lookup column loads and then trigger an event for the lookup column.
This article describes FEA for this case by taking an example list schema and configuration. You can adapt this as per your use case.
Requirement
- List Schema
- Departments
- Title
- Cost
- Requests
- Title
- Requester (person or group)
- Department (lookup to Departments list)
- Total Budget (Currency)
- Departments
- In Requests list new item form:
- Auto populate logged in user in “Requester” person or group column using auto-fill settings in NITRO Forms.
- Auto populate logged in user’s department (from user’s profile) in “Department” lookup column using auto-fill settings in NITRO Forms.
- Based on the “Department” column value, fetch the department item from “Departments” list and update the department cost in “Total Budget” column
Detailed steps:
Below configurations are in NITRO Forms for the ‘Requests’ list described above.
1. Configure Auto-fill User Information
Configure auto-fill user information settings to populate the logged in user and the user’s department in “Requester” and “Department” lookup column.
Go to the list -> List Settings -> Crow Canyon NITRO Forms -> Auto-fill User Information under “Form Settings” and configure as shown below:
2. Configure form event actions
We will configure two Form Event Actions:
- Form Event Action 1: Wait for the department lookup column to get loaded and value to get auto filled.
- This action is not required if user is directly selecting the department column value. In that case FEA 2 is enough as it will trigger when user selects a value.
- It is required in this special case to trigger the second FEA as it will not trigger if department value is set with user auto fill.
- Form Event Action 2: Update total budget
- This is the normal FEA to fetch department list item and use it to set value in a column in Request list.
- It is triggered whenever department column value is changed.
Configure form actions as shown below:
1. Form Event Action 1: Action to wait for department lookup column to load on the form
This action will execute a script that will check and wait for the “Department” lookup column value to get filled.
Action 1: Wait For Department Load
Configure execute script action as shown below:
Script:
Download the script from below:
Note: In above downloaded script, replace “Department” with actual column internal name.
To know the column internal name, please refer this article
Action 2: Set Department to trigger Event
Configure update form control action to trigger the event for ‘Department’ column value change. For this we need to do a dummy update of the “Department” column value.
Form Event Action 2: Update total budget
Configure form event action as shown below:
Action 1: GetDepartment
Configure fetch item action to get the item from “Departments” list
Value used in query builder condition:
Action 2: Update total budget
Configure update form control action to update the “Total Budget” with “Cost” from the department item.
Value used in column mappings:
CCSQLGetDepartment##[Cost|Cost]