- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:24 PM
Hi All,
I am new to scripting and trying to get my head around with UI action script and making fields mandatory. I have built the script based on https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/ . The script is performing field validation but it seems like if I update any one mandatory field with some data and click the button it moves ahead and updates the record. It should not submit the form until all the mandatory fields are updated.
Please advise what am i doing wrong with the below script:
function pending() {
if ((g_form.getValue('category') == '') && (g_form.getValue('u_alignment') == '') && (g_form.getValue('u_overview') == '') && (g_form.getValue('u_solution') == '')) {
g_form.setMandatory('category', true);
g_form.setMandatory('u_alignment', true);
g_form.setMandatory('u_overview', true);
g_form.setMandatory('u_solution', true);
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'pending_solution_approval'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = '150';
current.update();
action.setRedirectURL(current);
}
Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:56 PM
Hi,
update as this
function pending() {
var flag = false;
if (g_form.getValue('category') == ''){
g_form.setMandatory('category', true);
flag = true;
}
if(g_form.getValue('u_alignment') == ''){
g_form.setMandatory('u_alignment', true);
flag = true;
}
if(g_form.getValue('u_overview') == ''){
g_form.setMandatory('u_overview', true);
flag = true;
}
if(g_form.getValue('u_solution') == ''){
g_form.setMandatory('u_solution', true);
flag = true;
}
if(flag)
return false; //Abort submission
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'pending_solution_approval'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = '150';
current.update();
action.setRedirectURL(current);
}
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
02-17-2022 07:11 PM
Hi,
you can check which field is not filled and then show the consolidated message
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
02-17-2022 07:35 PM
Hi
Can it not be dynamic ? or it has be static message ?
if(flag)
alert('Please update fields in category, alignment, overview & solution');
return false; //Abort submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 08:05 PM
Hi,
you can append the field name in every if statement since you know which field is missing
at the end show that combined message
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader