The CreatorCon Call for Content is officially open! Get started here.

Change Model Restriction to Some Group Members

tarun12
Tera Contributor

Hello All,
I want my change request to be available only for certain Assignment groups based on my Assignment group department value. (Department value is a custom field on my groups table). If the Department value is only something XXX then for those Assignment groups only it should be visible. Therefore for other Assignment groups it should not be visible in change landing page. How to achieve using scripting in available for section in change model. Can anyone help me on this.

Thanks in advance.

10 REPLIES 10

@Ashwin Perumal1 

so if logged in user belongs to any group which has Department value as XXX then it should be shown?

If the above is correct then do this

var rec = new GlideRecord('sys_user_grmember');
rec.addQuery('user', user_id);
rec.addQuery('group.departmentField', 'XXX'); // give the correct field name and correct value to compare

// if the department field is reference then give sysId to compare

rec.setLimit(1);
answer = rec.hasNext();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 
It's not restricting the change model. Its not working even after giving correct field name and value

@Ashwin Perumal1 

share your script and what analysis have you done so far?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 
I have used your same script just replaced department field with proper field name and values|

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user_id);
gr.addQuery('group.u_department_label', 'e2571798875229101c2c2029dabb35b4'); //
gr.setLimit(1);
answer = gr.hasNext();



@Ashwin Perumal1 

u_department_label is reference field? referring which table?

are you using correct sysId to compare

did you add logs and check?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader