- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 04:36 AM
Hello All,
I have a UI action called "L3 Support", when clicked redirects us to a new form.
But I have a requirement, when only this particular UI action button is clicked, it should not check for any mandatory fields.
It should redirect us to the new form without validating for the mandatory fields or even when mandatory fields are not filled in.
UI action Script:
// Client side onclick function
function createl3support(){
if (g_form.getValue('comments') == '') {
// Remove any existing field message, set comments mandatory, and show a new field message
try {
g_form.hideFieldMsg('comments');
} catch(e) {}
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments', getMessage('Please enter a comment to open L3 Support case'), 'error');
return false; // Abort submission
}
// Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'l3_support'); // MUST call the 'Action name' set in this UI Action
}
if (typeof window == 'undefined')
serverReopen();
function serverReopen() {
// Set Incident state to active, update and reload the record
var l3support = new GlideRecord("sn_customerservice_l3_case_type");
l3support.newRecord();
l3support.short_description = current.short_description;
l3support.description = current.description;
l3support.asset = current.asset;
l3support.product = current.product;
l3support.assignment_group = "b85d44954a3623120004689b2d5dd60a";
l3support.parent = current.sys_id;
l3support.u_parent_case = current.sys_id;
//l3support.insert();
action.openGlideRecord(l3support);
//action.setRedirectURL(answer);
gs.addInfoMessage(gs.getMessage("New case opened"));
}
Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 05:52 AM
Hello Ankur,
I tried the above script and it bypasses the mandatory check, but doesn't perform, the new form redirection and copying fields over is also not happening.
I added to my script the below code and it worked fine for me:
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setMandatory(fields[x], false);
}
Thanks for your reply.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 05:14 AM
Hi Hardik,
Have you tried setting current table/form's mandatory fields as false in UI Action script before it redirects to the new form. Also, you might want to check Client checkbox in UI action to make this work.
E.g. : g_form.setMandatory('comments', false);
Please mark correct/helpful if applicable.
Regards,
Shubham
Shubham Tipnis
ServiceNow Enthusiast
⭐️ 3x Rising Star (2022–2024) – ServiceNow Community
Sharing insights, use cases & real-world learnings from the Now Platform
Always learning. Always building.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 05:39 AM
Hii Shubham,
Thanks for your reply.
Client checkbox is true. and the mandatory fields are coming from other ui policies and client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 05:46 AM
please check script shared by me in below comments.
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-28-2021 05:29 AM
Hi,
try to update as this
1) your UI Action name set as sysverb_cancel
2) update script as this
// Client side onclick function
function createl3support(){
if (g_form.getValue('comments') == '') {
// Remove any existing field message, set comments mandatory, and show a new field message
try {
g_form.hideFieldMsg('comments');
} catch(e) {}
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments', getMessage('Please enter a comment to open L3 Support case'), 'error');
return false; // Abort submission
}
// Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'sysverb_cancel'); // MUST call the 'Action name' set in this UI Action
}
if (typeof window == 'undefined')
serverReopen();
function serverReopen() {
// Set Incident state to active, update and reload the record
var l3support = new GlideRecord("sn_customerservice_l3_case_type");
l3support.newRecord();
l3support.short_description = current.short_description;
l3support.description = current.description;
l3support.asset = current.asset;
l3support.product = current.product;
l3support.assignment_group = "b85d44954a3623120004689b2d5dd60a";
l3support.parent = current.sys_id;
l3support.u_parent_case = current.sys_id;
//l3support.insert();
action.openGlideRecord(l3support);
//action.setRedirectURL(answer);
gs.addInfoMessage(gs.getMessage("New case opened"));
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader