The CreatorCon Call for Content is officially open! Get started here.

How to Check Multiple Mandatory fields in UI action

RudhraKAM
Tera Guru

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());
}

1 ACCEPTED SOLUTION

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());
}

View solution in original post

9 REPLIES 9

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());
}

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!

just return shows error 

unreachable return after return 

 

and with if condition not sure what to use in that condition 

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!

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!