Using Display Business Rule: If User is Service Desk group then only populate Manager field on incident form

Shawn33
Tera Expert

If the User is belongs to Service Desk group member then only populate Manager field on incident form , need to achieve this by using Display BR

1 ACCEPTED SOLUTION

Raghu Ram Y
Kilo Sage

HI @Shawn ,

Try below...Working...Tested..

Create Display Business rule and use the below code..

(function executeRule(current, previous /*null when async*/) {
 g_scratchpad.checkuser = gs.getUser().isMemberOf(gs.getProperty('checkUserInGroup'));
})(current, previous);

Note: As part of best practice, I have used "System Property" instead of passing group name directly here..

 

To create system Property do like below screenshot.

1. In Navigator type "sys_properties.LIST" and create a new one as below.

find_real_file.png

In Value pass the group SysId and in type select as "String"

 

Then Create Client script and use the below code.

 if (g_scratchpad.checkuser == true) {
        g_form.setValue('u_manager_new', g_user.userID);
    }

I hope it definitely helps you, if so please mark my response as correct and helpful

View solution in original post

7 REPLIES 7

Hi,

you can use this

Display BR:

(function executeRule(current, previous /*null when async*/) {
	
	g_scratchpad.isMember = gs.getUser().isMemberOf('Service Desk');
	
})(current, previous);

onLoad client script

function onLoad(){
	if(g_scratchpad.isMember.toString() == 'true')
		g_form.setValue('caller_id', g_user.userID);
}

Regards
Ankur

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

Raghu Ram Y
Kilo Sage

HI @Shawn ,

Try below...Working...Tested..

Create Display Business rule and use the below code..

(function executeRule(current, previous /*null when async*/) {
 g_scratchpad.checkuser = gs.getUser().isMemberOf(gs.getProperty('checkUserInGroup'));
})(current, previous);

Note: As part of best practice, I have used "System Property" instead of passing group name directly here..

 

To create system Property do like below screenshot.

1. In Navigator type "sys_properties.LIST" and create a new one as below.

find_real_file.png

In Value pass the group SysId and in type select as "String"

 

Then Create Client script and use the below code.

 if (g_scratchpad.checkuser == true) {
        g_form.setValue('u_manager_new', g_user.userID);
    }

I hope it definitely helps you, if so please mark my response as correct and helpful

Raghu Ram Y
Kilo Sage

Hello @Shawn,

Glad to know that you got the solution..

But here I too suggested the same solution and also as a first response but not sure my solution was missed to mark it as correct/Helpful.

No problem, but a suggestion passing "Group Name" is not a best practice to use beacuse at later point of time if there is some requirement to update the group name then your script will get fail, so it's a best practice to use system property.