g_form.setMandatory in client script is not working on the workspace but working in native view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
g_form.setMandatory in client script is not working on the workspace but working in normal view.
OnChange Client script
OnChange Field Name : Account
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
var gId = '1234493d47ba6a507c23de79116d7890';
if (newValue ===gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}
return;
}
gId = '1234493d47ba6a507c23de79116d7890';
if (newValue ===gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
screenshots please and client script config screenshot as well
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
what debugging did you do?
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var gId = '1234493d47ba6a507c23de79116d7890';
if (isLoading || newValue === '') {
if (newValue === gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}
return;
}
if (newValue == gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@Ankur Bawiskar If we select "1234493d47ba6a507c23de79116d7890" account and save it and reload the same form in workspace.. then it shows mandatory.. and remaining scenarios it was fine.
same happened with my script and your script also.
