NITRO Forms: Set column values back to the original if any validation fails during save.

Applies to: SharePoint online and On-premises (2013, 2016, 2019 and SE)

Description:

NITRO Forms provides enhanced capabilities to create, view or modify the SharePoint list items. For any specific cases not covered directly by the configurations, custom JavaScript can be added using ‘Submit Action’ and ‘Script Action’ in NITRO Forms.

For more details about ‘Submit Action’ and ‘Script Action’, refer to this article.

On ‘Submit Action’ button click, we can set column values on the form using custom JavaScript. For example, a form may have two buttons – ‘Submit for Approval’ and the normal ‘Save’ button. On clicking ‘Submit for Approval’ button, ‘Approval Status’ column value can be automatically set to the ‘Pending Approval’ status. This way user need not manually set the value and as per the action taken one or more column values can be auto-set.

However, if any validation fails then form will not be submitted, and user will need to modify the form data before submitting again. In this case, the column values that were set with custom JavaScript will not get reverted to original values. For example, if user clicked ‘Submit for Approval’ button the script will set the status. In case of any validation failure, user may decide to just save the item as draft and come back later for approval submission. In this case, it is necessary to revert the ‘Approval Status’ column value as it should not remain as ‘Pending Approval’.

This article describes the instructions to revert column values on the form if any validation fails after clicking submit action button.

Detailed Description

  1. This article uses ‘Requests’ list and it has below columns:
Column NameColumn Internal NameColumn Type
TitleTitleSingle line of text
Request StatusRequestStatusChoice type of column Options: UnassignedAssignedResolvedClosed
ResolutionResolutionMultiple lines of plain text
Assigned StaffAssignedStaffPerson or Group
RequesterRequesterPerson or Group
Process LogProcess LogMultiple lines of plain text
  • Configure validation on ‘Resolution’ column to make this column as required if “Request Status” is set to “Resolved”.
  • Configure a submit action ‘Resolve’ on the form, this will set the ‘Request Status’ to ‘Resolved’ and if any validation fails then it will set the ‘Request Status’ column value back to its original value.

Instructions

  1. Configure validation on ‘Resolution’ column.

Go to the list à List Settings à Crow Canyon NITRO Forms à Select the ‘Resolution’ column à Configure the column validation in ‘Column Settings’ as shown below:

Apply the Column Settings.

  • Configure ‘Resolve’ submit actions as shown below. This button will be shown in edit form, and it will set the ‘Request Status’ to ‘Resolved’. If any validation fails, then it will revert the ‘Request Status’ column to its original value.

Expand ‘Actions’ section from left hand panel and drag and drop ‘Submit Action’ on to the form.

  • Configure submit action as shown below:

Pre-Save script used above

var currentStatus = currentItem.get_item("RequestStatus");
formContext.setColumnControlValueByName("RequestStatus", "Resolved");
var listColumnValueobj = {};
var advSettings = { Validate : true, Fail: function(){
formContext.setColumnControlValueByName("RequestStatus", currentStatus);
}};
listColumnValueobj["ProcessLog"] = "Request is resolved.";
functionCallback(false, listColumnValueobj, "Default", advSettings)
  • Apply the settings and publish the form.

Sample Output:

If validation is successful:

Clicking ‘Resolve’ button will set the ‘Request Status’ column value to ‘Resolved’ and item will be saved.

If validation fails: