- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 07:20 AM
I have a use case in UI action if the fields are empty we need to abort the action and display mandatory message ,, we already has UI policies for making mandatory for those fields , but when i click on UI action it is ignoring the mandatory conditions
function close(){
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
var gDialog = new dialogClass('close2_record');
gDialog.setTitle('Publish ' + g_form.getValue('display_name') + ' to record Catalog');
gDialog.setPreference('sysparm_sys_id', g_form.getValue());
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 09:11 AM
Try this ... I tested it out in a DEV instance. It will print the Error Message just like your UI Policy would.
function close(){
var arr = g_form.getMissingFields();
var labels = [];
if (arr.length > 0) {
for (var i = 0; i < arr.length; i++) {
labels.push(g_form.getLabelOf(arr[i]));
}
g_form.addErrorMessage('The following mandatory fields are not filled in: '+labels.toString());
return;
}
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
var gDialog = new dialogClass('close2_record');
gDialog.setTitle('Publish ' + g_form.getValue('display_name') + ' to record Catalog');
gDialog.setPreference('sysparm_sys_id', g_form.getValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 07:37 AM
Hi,
Please see this article for mandatory field check:
https://community.servicenow.com/community?id=community_blog&sys_id=a95d6629dbd0dbc01dcaf3231f961982
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 08:28 AM
Hello Allen
by adding this line to my code seems working to display the alert message
But how to abort the action if the alert is popup /mandatory fields are not filled
function close(){
var arr = g_form.getMissingFields();
alert("The ID s of fields that are mandatory are not filled : " + arr);
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
var gDialog = new dialogClass('close2_record');
gDialog.setTitle('Publish ' + g_form.getValue('display_name') + ' to record Catalog');
gDialog.setPreference('sysparm_sys_id', g_form.getValue());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 08:34 AM
function close(){
var arr = g_form.getMissingFields();
if (arr.length < 0) {
alert("The ID s of fields that are mandatory are not filled : " + arr);
return;
}
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
var gDialog = new dialogClass('close2_record');
gDialog.setTitle('Publish ' + g_form.getValue('display_name') + ' to record Catalog');
gDialog.setPreference('sysparm_sys_id', g_form.getValue());
}
This will cancel out of the UI Action if there is nothing in the arr variable, but it will not reset whatever values the user has already put into the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 08:57 AM
Its still not working 😞