Condition in an edit button

Juan18
Tera Contributor

Hi all,

 

I need to do a condition in an edit button to show this button only to the assignment group in a table. How can I take the current assignmet group in the condition?

 

Thanks a lot

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hello @Juan18 

Can you let us know which table the edit button places..??

 

Can you try like below :

 

 

current.assignment_group = 'sys_id of group'

 

 

VishalBirajdar_0-1705655554441.png

 

 

**Note : Not to hardcode sys_id

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

In sn_hr_core_case table. The current object is not running in this case. Looks like "edit" button is special.

is it possible to share some screenshot please...!!!

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Rajdeep Ganguly
Mega Guru


Sure, you can achieve this by using the GlideRecord API to query the assignment group from the current record. Here's a step-by-step guide:

1. First, you need to get the sys_id of the current user. You can use the gs.getUser() method to get the current user and then get the sys_id from it. Here's a sample code:

javascript
var userID = gs.getUser().getID();


2. Next, you need to query the sys_user_grmember table to check if the current user is a member of the assignment group. Here's a sample code:

javascript
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userID);
gr.query();


3. Inside the query, you need to check if the group of the user matches the assignment group of the current record. Here's a sample code:

javascript
while(gr.next()) {
if(gr.group.getDisplayValue() == current.assignment_group.getDisplayValue()) {
return true;
}
}
return false;


4. The complete code would look like this:

javascript
var userID = gs.getUser().getID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userID);
gr.query();
while(gr.next()) {
if(gr.group.getDisplayValue() == current.assignment_group.getDisplayValue()) {
return true;
}
}
return false;


5. You can put this code in the 'Condition' field of the UI Action for the edit button. This will make the button visible only to the members of the assignment group.

Please note that this code assumes that the assignment group is stored as a string in the record. If it's stored as a reference to a group record, you might need to adjust the code accordingly.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER