How to show Field Info message & Field error message on some condition ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 06:06 AM
Hi All,
I have 3 varibales suppose A, B, C refering to the user table, If A=B, then it will show a field info message under the B field. If A=B=C, then it will show error message under the C field and clear the value of C as well.
I have tried the below , but its not working.
if (g_form.getValue('field_name') == g_form.getValue('field_name')) {
g_form.showFieldMsg('field_name', 'It cannot be the same person.', 'info', true);
}
else if ((g_form.getValue('field_name') == g_form.getValue('field_name')) &&(g_form.getValue('field_name') == g_form.getValue('field_name'))) {
g_form.clearValue('field_name');
g_form.showErrorBox('u_regional_director', 'Please note that the Hiring manager, Department head and Regional director cannot be the same person.', 'error');
}
}
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 02:53 AM
if your task is to restrict values based on other variables then use ref qualifier.
Why to allow user to select the value and then run the validation if the record selected is valid or not? it's bad user experience.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 03:16 AM
Hi
You concern is right , but I have 3 variables where 2 varibales can be same values and 3 varibales can not be same values , In this case ref qualifier will work or not .
And I hvae tried the below ref qualifier, still its not working.
'active=true^sys_idNOT IN' + current.variables.u_hiringmanager+ ',' + current.variables.u_department_head;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 03:31 AM
Hi,
then you just need to validate if all 3 values are unique because 2 variables which can have same value can be AB or AC or BC
then use onSubmit
function onSubmit(){
var arr = [];
arr.push(g_form.getValue('field_name1').toString());
arr.push(g_form.getValue('field_name2').toString());
arr.push(g_form.getValue('field_name3').toString());
var isUnique = checkIfArrayIsUnique(arr);
if(!isUnique){
alert('Please note that the Hiring manager, Department head and Regional director cannot be the same person.');
return false;
}
}
function checkIfArrayIsUnique(arr) {
var map = {}, i, size;
for (i = 0, size = arr.length; i < size; i++){
if (map[arr[i]]){
return false;
}
map[arr[i]] = true;
}
return true;
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 03:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 03:50 AM
Hi,
alert will only show when there is no unique sysId
did you alert what comes in that array?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader