need to make variable mandatory and visible for specific group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:20 AM
Can anyone please help me on the below requirement. Need to make one variable visible when the logged in user is member of specific group and need to make mandatory if the variable request type is assign or delete.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:22 AM
Hi,
You'd need to utilize GlideAjax in client script to go and check their membership and if true AND the field has a value you're looking for, then set the field to mandatory true.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:44 AM
Hello Allen,
I have tried with script include and client script. But if answer is true and req=='Assign' it is not working. Can you please let me know where is the mistake.
function onLoad() {
var req = g_form.getValue('request_type');
//Type appropriate comment here, and begin script below
var ga = new GlideAjax("sdmebers"); //name of script include
ga.addParam("sysparm_name", "validdate zitk"); //name of function
ga.getXMLAnswer(callBack); //name of call back function
function callBack(answer) {
if (answer == 'true' && req == 'Assign'){
g_form.setVisible('request_opm_order_email', true);
g_form.setMandatory('request_opm_order_email', true);
} else {
g_form.setMandatory('request_opm_order_email',', false);
g_form.setVisible('request_opm_order_email', false);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:34 AM
Hi,
first type error g_form.setMandatory('request_opm_order_email',', false);
should be
g_form.setMandatory('request_opm_order_email', false);
if not works try below it should be easy.
You can create display business rule and client script use below script. using g_scratchpad you can set mandatory.
Business rule:
(function executeRule(current, previous /*null when async*/ ) {
var grusr = new GlideRecord('sys_user_grmember');
grusr.addQuery('group', 'group_sys_id'); //give group sysid here
grusr.addQuery('user', gs.getUserID());
grusr.query();
if (grusr.hasNext()) {
g_scratchpad.fieldmadatory = true;
}
})(current, previous);
Client Script:
function onLoad() {
var req = g_form.getValue('request_type');
if (g_scratchpad.fieldmadatory == true &&req=='Assign') {//if it is choice check choice value
g_form.setVisible('request_opm_order_email', true);
g_form.setMandatory('request_opm_order_email', true);
} else {
g_form.setMandatory('request_opm_order_email', false);
g_form.setVisible('request_opm_order_email', false);
}
}
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 01:38 PM
Hi,
You'd need to utilize GlideAjax in client script to go and check their membership and if true AND the field has a value you're looking for, then set the field to mandatory true.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!