- 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-16-2022 08:54 PM
Hi,
check for each field separately
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-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-16-2022 09:06 PM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 02:39 PM
Hi
I am not getting message "The mandatory fields are not filled: xxxx" is there any way to populate this ? I was getting mandatory field message in my previous script.
Let me know.
Thanks