Skip to content

Commit 34266af

Browse files
kmxokmxo
and
kmxo
authored
validate (#1085)
Co-authored-by: kmxo <[email protected]>
1 parent a3d0bc8 commit 34266af

File tree

2 files changed

+62
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)