- 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 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 08:35 AM
Just return; or try return false; something like that.
You could do if statement and then evoke another function...a few ways.
Please mark reply as Helpful/Correct. 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 09:01 AM
just return shows error
unreachable return after return
and with if condition not sure what to use in that condition

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2019 09:22 AM
function close(){
var arr = g_form.getMissingFields();
alert("The ID s of fields that are mandatory are not filled : " + arr);
if (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());
}
}
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-20-2019 05:38 AM
Hi,
Since you marked someone else's response as Correct, as I was helping you...could you at least marked my post as Helpful...especially the one where you used the resource I mentioned...
g_form.getMissingFields();
Thanks...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!