setMandatory is not working in my onchange script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 03:43 AM
This my onChange Client script that makes the comment field mandatory if correct state is selected.
My problem is that if i select state(1,2,4) the comment field will become mandatory and I select state(3), it wont become mandatory.
Could you help me on this, i don't know the root cause of this script because they are in the same IF.
Here is my code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var state = newValue;
if(state == '1' || state == '2' || state == '3' || state == '4'){
form.setMandatory('comments', true);
}
}
thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 03:48 AM
Hi John,
I'm sure it is just a typo, but if not, please use g_form.setMandatory("comments", true);
Also, since this script is working for other states, check if there's any UI policy or other script that might be causing comments to not be mandatory.
Hope that helps.
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 03:54 AM
Sorry for the typo
There is no UI policy running. just the Script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 04:02 AM
Hi John,
Let us simplify this even further. Put two alerts before and after the if condition to check if the control reaches till the comments part.
var stateValue = newValue;
alert("State is "+stateValue);
if(stateValue == '1' || stateValue == '2' || stateValue == '3' || stateValue == '4'){
alert("should set comments mandatory");
form.setMandatory('comments', true);
}
See, what responses you get for states 1 or 2 or 4 and for state 3.
Hope that helps.
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 04:07 AM
Hi mandar,
I already did that and alerts for the all the state with correct value but still the comment is not mandatory.