Applies To: SharePoint Online and On-premises
Description
NITRO Forms column validation feature supports validating column values based on:
- Pattern: Like phone number, email and custom regular expression based patterns
- Length: To check if amount of data entered in column is equal to/less than/more than the required length
- Value: To check if data entered in columns is matched with specified value based on the selected operator
- Script: For custom validation cases like to check column value based on data entered in other columns
This article describes the sample use cases for custom script validations. For more details regarding validations, please refer this article.
Use Case 1
Configure validation on a date column so that entered date should be at least 14 days from today. In this example we have considered ‘Due Date’ column in Tickets list.
Go to Site Contents -> Tickets -> List Settings -> Crow Canyon NITRO Forms -> Select “Due Date” column -> Column Settings panel (on the right) -> Add Validation.
Select ‘Script’ option and configure the custom script given below.
Script:
var minDate = new Date();
minDate.setDate(minDate.getDate() + 14);
var DueDate = new Date(objData.ColumnValue);
if(minDate > DueDate){
objData.Status = false;
objData.Message = "Due Date cannot be less than 14 days from today";
}
return objData;
Sample Output:
Use Case 2
Configure validation on Due Date column based on Priority column.
Priority Column value | Validation |
High | Due Date < Today + 7 (Due Date should not be beyond 7 days from Today) |
Other | Due Date < Today + 14 (Due Date should not be beyond 14 days from Today) |
Go to Tickets -> List Settings -> Crow Canyon NITRO Forms -> Due Date column and configure the validation as shown below.
Go to Site Contents -> Tickets -> List Settings -> Crow Canyon NITRO Forms -> Select “Due Date” column -> Column Settings panel (on the right) -> Add Validation.
Script:
var DueDate = new Date(objData.ColumnValue);
var Priority = objData.FormContext.fetchColumnValueUI("Priority1");
if(Priority == "High") {
var maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 7);
if(maxDate < DueDate) { objData.Status = false; objData.Message = "Due Date should be less than 7 days from today for high priority Tickets"; } } if(Priority != "High") { var maxDate = new Date(); maxDate.setDate(maxDate.getDate() + 14); if(maxDate < DueDate) {
objData.Status = false;
objData.Message = "Due Date can be less than 14 days from today";
}
}
return objData;
In the above script, replace “Priority1” column with internal name of the column as per our requirement.