Skip to content

Commit 3bf5729

Browse files
author
kmxo
committed
validate data field
1 parent 6000a91 commit 3bf5729

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Validating a data field in a Service Portal
3+
4+
Use Case: When submitting a Record Producer, a date field can’t be in the past. How to accomplish this?
5+
6+
We can create a Catalog Client Script.
7+
8+
1) What is the trigger?
9+
10+
The script will run when the date field value changed.
11+
12+
2) What do we need to confirm?
13+
14+
We need to check if the date provided is in the future.
15+
16+
3) What if the date is not in the future?
17+
18+
If the date is not in the future, then we show an error message to inform that the date cannot be in the past.
19+
20+
# Step by step process
21+
22+
1) Create a Record Producer (RP) and define the Catalog and Category so it will be visible in a Service Portal
23+
24+
2) Create a variable in your RP. In this example, the variable will have this configuration:
25+
26+
Type: Date
27+
Question: Project Deadline
28+
Name: project_deadline
29+
Mandatory: Yes (checked)
30+
31+
3) Create a Catalog Client Script in your RP to check if the project_deadline value changed. If the date is in the past, show an error message to the user.
32+
33+
Your Catalog Client Script will look like this:
34+
35+
Name: Validate Project Deadline
36+
Applies to: A Catalog Item
37+
UI Type: Mobile / Service Portal
38+
Type: onChange
39+
Variable name: project_deadline
40+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
3+
if (isLoading || newValue == '') {
4+
g_form.hideFieldMsg('project_deadline', true);
5+
return;
6+
}
7+
8+
//If the Project Deadline is in the past, show error message
9+
var deadlineDate = new Date(getDateFromFormat(newValue, g_user_date_format));
10+
var nowDate = new Date();
11+
12+
if (nowDate.getTime() >= deadlineDate.getTime()) {
13+
14+
g_form.setValue('project_deadline', '');
15+
g_form.showErrorBox('project_deadline', 'Project deadline should be after today', true);
16+
17+
} else {
18+
19+
g_form.hideFieldMsg('project_deadline', true);
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)