Catalog client script for making field mandatory based on condition

Akshaya14
Tera Contributor

Hi Team,

I have a reference field(group) if group is selected it auto populate the group manager in another string field. I need to check two condition in String field.

1. After populating the group manager, if Group manager is inactive then need to make one check box mandatory and show field message in string field.

2. If Group manager is not present in group table, will get empty string field, then need to make same  check box mandatory and show field message in string field.

I wrote the onchange client script for string field 

function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('group_owner_dl', doAlert); // doAlert is our callback function
var grp = g_form.getValue('group_owner_dl');


function doAlert(caller) { //reference is passed into callback as first arguments

if ((caller.active == 'false') && (grp != ""))

{

g_form.showFieldMsg('group_owner_dl', 'Group Owner is inactive. Please Add new group owner');

g_form.setMandatory('change_group_owner', true);

}

else if ((grp == "") && (group_to_be_modified_dl)) {
g_form.showFieldMsg('group_owner_dl', 'Group Owner is Empty. Please Add new group owner');
g_form.setMandatory('change_group_owner', true);

else

{
g_form.hideFieldMsg('group_owner_dl', false);
g_form.setMandatory('change_group_owner', false);
}

}
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshaya14 

you cannot dot walk to 2 levels in client script so you need to use GlideAjax to know manager is inactive or not

Do all the logic in script include function and in client side just add the message and mandatory logic

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshaya14 

you cannot dot walk to 2 levels in client script so you need to use GlideAjax to know manager is inactive or not

Do all the logic in script include function and in client side just add the message and mandatory logic

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader