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

Assign to field values on visible if logged in user is member of the group

Arun_Manoj
Mega Sage

Hi,

 

Assign to field values only visible to logged in user is a member of the selected group.

 

Eg : I'm not a member of that group,then I select assign to field it needs show empty, otherwise if I'm member of the corresponding group then group members name needs to show 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Arun_Manoj 

why not show that field only to those group members?

Create field level READ ACL on Assigned to field and use script in advanced script

answer = gs.getUser().isMemberOf('groupName');

OR

You can use onLoad client script + Display BR for this and hide it

(function executeRule(current, previous /*null when async*/) {
    // Get the group sys_id for group ABC
    var groupSysId = 'YOUR_GROUP_SYS_ID'; // Replace with the actual sys_id of group ABC
    g_scratchpad.showAssignedTo = gs.getUser().isMemberOf(groupSysId).toString();
   
})(current, previous);
function onLoad() {
    // Check the scratchpad value set by the Display Business Rule
    if (g_scratchpad.showAssignedTo === 'false') {
        // Hide the Assigned To field if the user is not in group ABC
        g_form.setDisplay('assigned_to', false);
    }
}

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

@Arun_Manoj 

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

Anand Kumar P
Giga Patron

Hi @Arun_Manoj ,

 

Which table you have this assigned to field?

 

If you want to show assigned to field if user part of specific group then go with Ankur solution.

 

It’s business usecase or your doing in pdi. Best way to do is depends on assignment group show assigned to users part of that group.

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

 

 

Sanjay Bagri1
Tera Guru
Tera Guru

Hello @Arun_Manoj ,

 

I have tried this in Incident table and its working fine and Thank you Ankur your scripts was giving result as expected.

 

First you can write a Display BR. in incident table: 

 

 

(function executeRule(current, previous /*null when async*/) {

    // its giving all groups dynamically to pass in scratch pad variable
    g_scratchpad.showAssignedTo = gs.getUser().isMemberOf(current.assignment_group).toString();
   
})(current, previous);

 

 

Write the Onload Client script : 

 

 

function onLoad() {
  
     if (g_scratchpad.showAssignedTo === 'false') {
        // Hide the Assigned To field if the user is not in XYZ group 
        g_form.setDisplay('assigned_to', false);
    }
}

 

 

 

Output: 

Current logged in USer is not part of Software group so hiding the Assigned to Feild. 

SanjayBagri1_0-1734618667897.png

 

user is part of hardware group so he is able to see

SanjayBagri1_1-1734618759654.png

 

 

If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

Thanks

Sanjay Bagri