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 04:22 AM
Hi,
did you check what came in the isUnique variable?
alert(isUnique);
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 04:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 04:36 AM
Hi,
I didn't the case.
You are saying 2 variables can be same but all 3 must be unique
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 04:40 AM
Let me explain ,
2 variables can be same , but 3 can not be same .
-If 2 variables are same and another one is different then it will allow to submit the request.
- If 3 varibales are same then it will not allow to submit, this is the only case where it should not allow or any other combination it will allow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 04:51 AM
Hi,
then you can do this
function onSubmit(){
var arr = [];
var val1 = g_form.getValue('field_name1').toString();
var val2 = g_form.getValue('field_name2').toString();
var val3 = g_form.getValue('field_name3').toString();
if(val1 == val2 || val1 == val3 || val2 == val3){
// do nothing as it should be allowed
}
else{
arr.push(val1);
arr.push(val2);
arr.push(val3);
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