- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:05 PM
Hello,
I have a catalog client script that uses the onLoad() method to remove mandatory fields on a form load. There is one field that is a "Yes/No" type. If that field is set to "Yes" another field displays and is mandatory. My onLoad() script isn't making that field NOT mandatory. Any suggestions?
Below is what I am currently doing:
function onLoad() {
var ga = new GlideAjax('getUserInfo');
ga.addParam('sysparm_name', "isMemberOfGroup");
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'true') {
g_form.setMandatory('order_type', false);
g_form.setMandatory('order_date', false);
}
});
if (g_form.getValue('delivery_preference') == 'Yes') {
g_form.setMandatory('delivery_preferene_notes', false);
}
}
The part that is supposed to handle the onChange() are the last 2 lines:
if (g_form.getValue('delivery_preference') == 'Yes') {
g_form.setMandatory('delivery_preferene_notes', false);
}
Anything helps,
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:31 PM
Hi,
onLoad client script can not be used as onChange but onChange client script can be used as onLoad, So you just need to change your client script from onLoad to onChange and use the below modified script for you
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
var ga = new GlideAjax('getUserInfo');
ga.addParam('sysparm_name', "isMemberOfGroup");
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'true') {
g_form.setMandatory('order_type', false);
g_form.setMandatory('order_date', false);
}
});
}
if(newValue===''){
return;
}
else if (g_form.getValue('delivery_preference') == 'Yes')
g_form.setMandatory('delivery_preferene_notes', false);
else
g_form.setMandatory('delivery_preferene_notes', true);
}
Kindly mark my answer as Correct and Helpful based on the Impact.
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:18 PM
hello mkader
You can use ui policy for 'if' part . In UI policy condition you should give like 'delivery_preference is true' then in action section you can make 'delivery_preference_notes' mandatory. And make sure 'onLoad' check box is unchecked.
If my answer solve your problem then mark it correct and helpful
Regards
Kunal Fule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:21 PM
Hi Mkedar,
You can just create new Catalog Client Script with the type onChange for that field yes/no if the value is Yes than set the another field is mandatory. and keep this onLoad Catalog client script as it is.
If my answer was able to solve your query please mark it as Helpful & Correct.
Thank you
Siddhnath Pandey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:29 PM
Both answers are definitely doable, but I want to be able to handle this within the same catalog client script if possible

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:31 PM
Hi,
onLoad client script can not be used as onChange but onChange client script can be used as onLoad, So you just need to change your client script from onLoad to onChange and use the below modified script for you
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
var ga = new GlideAjax('getUserInfo');
ga.addParam('sysparm_name', "isMemberOfGroup");
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'true') {
g_form.setMandatory('order_type', false);
g_form.setMandatory('order_date', false);
}
});
}
if(newValue===''){
return;
}
else if (g_form.getValue('delivery_preference') == 'Yes')
g_form.setMandatory('delivery_preferene_notes', false);
else
g_form.setMandatory('delivery_preferene_notes', true);
}
Kindly mark my answer as Correct and Helpful based on the Impact.
Regards,
Alok