Make field Mandatory using onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 09:18 AM
Hi,
I have a query.If i give configuration item and i should get it and check in relationship table child value is same as this ci and if the application is A then i should make a field B mandatory. Its working but when i change the value of Field B that mandatory is going and it becomes as non mandatory field? How to tackle this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 09:47 AM
@Divya Rajasekar Can you share your client script code here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 10:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 11:03 AM
Hi @Divya Rajasekar ,
Use below script
if (newValue === '') {
return;
}
if (oldValue != newValue) {
g_form.setValue('field_b', '');
g_form.setValue('field_b1', '');
}
var gn = new GlideAjax('testutils');
gn.addParam('sysparm_name', 'checkpartci');
gn.addParam('sysparm_sysid', newValue);
gn.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert('from script include' + answer);
if (answer == 'true') {
g_form.setDisplay('field_b', true);
g_form.setMandatory('field_b', true);
} else if (answer == 'false') {
g_form.setMandatory('field_b', true);
g_form.setDisplay('field_b', false);
}
}
Thanks,
Anand