We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

isOmitEditButton() condition in UI Action "Edit..." fails

Roman Haas
Giga Guru

Hi Community

I have a problem with the OOB UI Action "Edit...". Condition of this UI action is:

(new GlideRecord(current.getTableName())).canCreate() && RP.isManyToMany() && !RP.getListControl().isOmitEditButton()

Now on my User Group table, I want that only the group owner can see and use the "edit" button on the related list "Group Members". Therefore I edited the list control and added following omit edit button script:

var answer = true;

if(current.group.manager == gs.getUserID() || gs.hasRole('admin')){
	answer = false;
}

answer;

 

Now when a non-group-owner user opens the form, the edit button is omitted. If a group owner opens the form the edit is there but clicking it results in an "action not authorized". After investigating I know its the "!RP.getListControl().isOmitEditButton()" condition on the UI action. If I remove this everything works as expected.

 

Does anyone have an idea what's the cause?

 

Thank you in advance, regards

1 ACCEPTED SOLUTION

Problem solved!

 

In a list control of related list access to the main record displayed on the form you need to use "parent", and not "current" like I did. "Current" refers to the first entry of the related list.

 

So following list control omit edit function works like desired:

var answer = true;

if(parent.manager == gs.getUserID() || gs.hasRole('admin')){
	answer = false;
}

answer;

 

Thanks everyone 🙂

View solution in original post

6 REPLIES 6

Roman Haas
Giga Guru

I made an interesting observation. When I comment on the omit edit script on the list control it works as expected.

 

Not working -> action not authorized (admin user is working):

var answer = true;

if(current.group.manager == gs.getUserID() || gs.hasRole('admin')){
	answer=false;
}


answer;

 

Working:

var answer = true;

answer;

 

What could be wrong with this script?

 

Problem solved!

 

In a list control of related list access to the main record displayed on the form you need to use "parent", and not "current" like I did. "Current" refers to the first entry of the related list.

 

So following list control omit edit function works like desired:

var answer = true;

if(parent.manager == gs.getUserID() || gs.hasRole('admin')){
	answer = false;
}

answer;

 

Thanks everyone 🙂