Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide the "New" UI action button of the change_request from the related list of tasks.

Maria Sol Arauz
Tera Contributor

I need your help with a UI action on a related list of a change. I need to introduce the condition that the button disappears if the state of the change is implement, review, or scheduled. Can you help me?

3 ACCEPTED SOLUTIONS

Chaitanya ILCR
Mega Patron

Hi @Maria Sol Arauz ,

put this in the omit new script

 

var state = parent.state
if (state == -1 || state == -2 || state == 0)
    answer = true

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

@Maria Sol Arauz 

are you comparing correct state values?

also if you want to omit then ensure answer=true in script is set

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

View solution in original post

Hi @Maria Sol Arauz,

 

Correct. This is why I reversed the logic us not equal to ("!=")

I'm glad you got to the solution.

 

This also works using inverse logic:

Screenshot 2025-04-09 at 15.37.39.png

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

View solution in original post

9 REPLIES 9

Hi @Maria Sol Arauz and @Ankur Bawiskar - I'm not sure how this response solves the issue.

Based on the script provided, it's a logic issue.

 

Check my response and solution which resolves the issue. Providing this response so as to help @Maria Sol Arauz and the community when looking back at this in the future.

 

As the condition is for omitting, it's a double negative as it were. Additionally, you can't use || when checking for multiple values. It needs to be an && check. 

if (parent.state != -2 && parent.state != -1 && parent.state != 0) {
	answer = false;
}
else{
	answer = true;
}

 

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

Hi @Maria Sol Arauz,

 

Change your script to the following. This is tried and tested on my PDI.

(It's a logic thing... when you use || (or) you still match the other conditions.) The below resolves this.

 

if (parent.state != -2 && parent.state != -1 && parent.state != 0) {
	answer = false;
}
else{
	answer = true;
}

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

Since the button is "omit new button," the values of the answer must be true for the condition you want to hide it. I was doing it the other way around.

Hi @Maria Sol Arauz,

 

Correct. This is why I reversed the logic us not equal to ("!=")

I'm glad you got to the solution.

 

This also works using inverse logic:

Screenshot 2025-04-09 at 15.37.39.png

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

Chaitanya ILCR
Mega Patron

Hi @Maria Sol Arauz ,

put this in the omit new script

 

var state = parent.state
if (state == -1 || state == -2 || state == 0)
    answer = true

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya