Script Include

SamiranD
Tera Contributor

how to create multiple functions inside one script include in servicenow. I have one scenario - I need to make all the fields readonly if the user is part of a certain group group 1 and editable if the user is part of group2. But if the user is part of both the groups then the fields should be readonly.

please help me with the logic using script include and client script.

4 REPLIES 4

Vaibhav_Nikam
Tera Guru

Hello @SamiranD ,
You can do it in single function using the assign value to the return as 
1. Check if user is part of group1 but not group2 return it as grp1 ,
2.check if user is part of group2 but not group1 , then return as grp2,
3. Check if user is part of both group, return as both_grp

comparing with return value you can make fields visibility using g_form.setVisible();


If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.

Thanks,

Vaibhav Nikam

Ankur Bawiskar
Tera Patron
Tera Patron

@SamiranD 

you can use 2 approaches

1) Display business rule + onLoad client script

OR

2) onLoad client script + client callable script include

OR

3) table.* WRITE ACL with advanced script

something like this

var group1Member = gs.getUser().isMemberOf('Group 1');
var group2Member = gs.getUser().isMemberOf('Group 2');

if (group1Member)
    answer = false;
else if (group2Member)
    answer = true;
else if (group1Member && group2Member)
    answer = false;

what did you start with and where are you stuck?

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

@SamiranD 

Hope you are doing good.

Did my reply answer your question?

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

@SamiranD 

Hope you are doing good.

Did my reply answer your question?

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