UI Action condition not working es expected

Ajeet Kumar1
Mega Contributor

Hi All,

There is UI Action on problem table "Start Fix" and its out of box condition is:

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS)&&new ProblemStateUtils().
validateStateTransition(current,ProblemState.STATES.FIX_IN_PROGRESS)

I wanted to it to be visible to "XYZ" group only, so i added it like:

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS)&&new ProblemStateUtils().
validateStateTransition(current,ProblemState.STATES.FIX_IN_PROGRESS)&&gs.getUser().isMemberOf('XYZ')

This was working as i wanted but even it is restricting to "admin" as well if admin is not member of XYZ.

So again i changed the condition as below but it is still working as before, not showing "Satrt Fix" ui action to admin if admin is not member of XYZ.

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS)&&new ProblemStateUtils().
validateStateTransition(current,ProblemState.STATES.FIX_IN_PROGRESS)&&((gs.getUser().isMemberOf('XYZ'))||(gs.getUser.hasRole('admin')))

Please check and suggest me the solution.

Thanks

 

1 ACCEPTED SOLUTION

Knight Rider
Mega Guru

Hi Ajeet,

Try replacing with this in your condition. ||gs.getUser().hasRole('admin');

View solution in original post

12 REPLIES 12

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You are mentioning the below is working, though just not for admin? Is that correct?

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS)&&new ProblemStateUtils().
validateStateTransition(current,ProblemState.STATES.FIX_IN_PROGRESS)&&gs.getUser().isMemberOf('XYZ')

If so, you could encap this with () and add || gs.hasRole('admin'). So:

(current.canWrite() && (current.state != ProblemState.STATES.FIX_IN_PROGRESS) && new ProblemStateUtils().validateStateTransition(current, ProblemState.STATES.FIX_IN_PROGRESS) && gs.getUser().isMemberOf('XYZ')) || gs.hasRole('admin')

or:

current.canWrite() && (current.state != ProblemState.STATES.FIX_IN_PROGRESS) && new ProblemStateUtils().validateStateTransition(current, ProblemState.STATES.FIX_IN_PROGRESS) && (gs.getUser().isMemberOf('XYZ') || gs.hasRole('admin'))

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Thank you for looking at it.

Yes, you are right, I wants that Start Fix UI action should visibile only to XYZ group and admin.

(current.state != ProblemState.STATES.FIX_IN_PROGRESS) && new ProblemStateUtils().validateStateTransition(current, ProblemState.STATES.FIX_IN_PROGRESS) &&gs.getUser().isMemberOf('XYZ')  >>> This is working and only showing to XYZ group

now as per your suggestion modified it as below:

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS) && new ProblemStateUtils().validateStateTransition(current, ProblemState.STATES.FIX_IN_PROGRESS) &&(gs.getUser().isMemberOf('Problem Coordinators') || gs.getUser.hasRole('admin')) ----------- still admin can not see this UI action if admin is not member of XYZ.

Could you literally copy/paste the suggestions that I provided? What you pasted here, is not what I provided.

Also I provided two possibilities. Can you test both.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Knight Rider
Mega Guru

Hi Ajeet,

Start Fix  is an Out of the Box button instead of changing the condition in it directly, I recommend you to Inactive button and clone it so you can customize accordingly.

This is because, In future if there is an upgrade that OOB button will get updated. If you customize it the button will get excluded and no updates will happen to it in future.

 You can use below condition in your UI Action

current.canWrite()&&(current.state != ProblemState.STATES.FIX_IN_PROGRESS)&&new ProblemStateUtils().
validateStateTransition(current,ProblemState.STATES.FIX_IN_PROGRESS)&&(gs.getUser().isMemberOf('XYZ')||gs.getUser.hasRole('admin'))

Thanks!!

Please mark as Correct/Helpful, if this helps!!!