Condition for button was not working

Fahimas
Tera Contributor

Dear team,

              Iam new to serviceNow, i have an issue that my button is not visible even wheb the condition was true!

my condition is: current.state === 1 && gs.getUserID().isMemberOf(current.assignment_group)

explanation: the button must be visible when the state was new and the loggedin user was a member of the current assignment group.the button was not visible evn when condition become true.i impersonate myself as an member of the assignment grp and state was new but the prblm ws button wasnt visible.

preview: i have checked form button

                i have checked everything from reading other article evnthough itwasnot working

                

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Fahimas ,

 

 

 

The type of current.state will return an object and when you compare an object with number it will return you false, since you are using AND operator when the initial condition is false it will not test the other conditions. You can use == to compare state value.

 

And instead of getUserID use getUser(). getUser() return entire user object where as getUserID() return only the sys_id of the particular user.

 

current.state == 1 && gs.getUser().isMemberOf(current.assignment_group)

 

 

 

Mark this helpful/ Accept the solution if this helps.

View solution in original post

19 REPLIES 19

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Fahimas 

 

You need to update code like this try both ways

 

current.state == 1 && (gs.getUser().isMemberOf('Test1' ) || gs.getUser().isMemberOf('Test2'))

((current.state=='new' && gs.getUser().isMemberOf(current.assignment_group.toString())) || ((current.state=='open' && gs.getUser().isMemberOf(current.assignment_group.toString()))

 

https://www.servicenow.com/community/developer-forum/button-is-visible-for-certain-groups-at-specifi...

 

https://www.servicenow.com/community/developer-forum/ui-action-button-visible-only-to-people-of-a-sp...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Shivalika
Mega Sage

Hello @Fahimas 

 

Please check if the insert or update checkbox is checked to specify when the ui action will be visible. Also one of the form button, form menu should also be checked to make it visible. These are some small things apart from condition. But if neglected, the action wouldn't be visible. 

 

Regards, 

Shivalika Gupta 

Servicenow Developer - Schaeffler

Please mark my answer as helpful if it helped you in anyway. 

I haved checked it already!

I have checked them evethough it was not visible