- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 08:52 PM
hi
i have to write one client script on load of chg req that :
if (logged in user is ammber of group ='abc') {
g_form.setDisplay('cab_required', true); //cab required field is a checkbox field
var field = g_form.getValue('cab_required');
if (field == true) {
g_form.setValue('u_type', 'u_normal', 'Normal');
}
}
how to put this in syntax correctly
thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 02:02 AM
Hi,
Check the output and let me know what is it showing.
function onLoad() {
var display = g_scratchpad.display;
alert(display);
if (display == 1) {
alert("if1");
g_form.setDisplay('cab_required', true);
var field = g_form.getValue('cab_required');
alert(field);
if (field == true) { //is the syntax is proper
g_form.setValue('u_type', 'u_normal', 'Normal');
}
} else {
alert("else");
g_form.setMandatory('cab_required', false);
g_form.setVisible('cab_required', false);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 09:08 PM
Hi Dell,
You can write the following code to check group membership
if(gs.getUser().isMemberOf)
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=GUser-isMemberOf_S
Let me know if you have any questions.
Please mark this comments as Correct Answer/Helpful if it helped you.
Cheers,
Hardit Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 09:08 PM
Hi
what is the type of "u_type" field, I mean is it choice or string type any other
you can create one display business rule and get the group members and pass the g_scratchpad value into your onload client script it will return boolean values like true or false,
Display BR
g_scratchpad.group = gs.getUser().isMemberOf(current.assignment_group)
Client script
var grp = g_scratchpad.group
if (grp ='true') {
g_form.setDisplay('cab_required', true); //cab required field is a checkbox field
var field = g_form.getValue('cab_required');
if (field == true) {
g_form.setValue('u_type', 'u_normal', 'Normal');// setValue method we will pass only two parameters one is filed backend value and one is setting value
}
}
please hit like if it helps you and close the thread accordingly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 09:09 PM
Hi,
group membership cannot be checked in client script; use display business rule on that table and use this
BR Script:
g_scratchpad.isMember = gs.getUser().isMemberOf('ABC');
Client Script:
function onLoad(){
if(g_scratchpad.isMember){
// show or hide fields you want
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 10:13 PM
hi ankur,
can you explain your BR step by step and client script like on which table br is going to apply