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

Fahimas
Tera Contributor

I have already wrote that code even though it was not working 

@Fahimas 

It looks like you are not in Global scope. Please add toString() as:

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

 

I have just tried the same on a scoped app and it is returning true/false as expected.

 

If it is not working, could you please share if any error thrown in the logs as well as a screenshot from your UI Action.


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Fahimas
Tera Contributor

These was the code which I wrote first , it was not working so I have used another code 

Hemant Ch
Tera Expert

Check first whether the user is part of that assignment group or Not ?

 

Regards

Ch Hemant Kumar

Lead-Ciena

Ankur Bawiskar
Tera Patron
Tera Patron

@Fahimas 

are you sure you are comparing correct state value?

Did you try to debug 1 by 1 by removing the condition and see which one is failing?

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