Need help to write a Script to enable conditonal UI Action (button)

Kruthik45
Tera Contributor

Use case:- There should be a button (named as- Assigned Me) at the top, this button should only display to users who belongs to the selected assignment group mentioned below the Assignment group field in the incident record. Means when the logged in user selects the assignment group from the assignment group field and he belongs to that group then that button should be visible to him.

2 ACCEPTED SOLUTIONS

Hemanth M1
Giga Sage
Giga Sage

Hi @Kruthik45 ,

 

Create a UI action as below 

(Make sure you save the form once assignment group is selected to see UI hide/show logic)

HemanthM1_0-1724495916413.png

//Condition
gs.getUser().isMemberOf(current.assignment_group)

//script
current.assigned_to = gs.getUserID(); //set logged in user has assigned to
current.update(); //update

 

Hope this help!!!

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

Hi @Kruthik45 

 

Condition section is only to control button visibility (hide/show)

if you want to write multiple line then use &&, || conndition , if its multiple condition and does fit in the condition section use script include and call it from condition section

 

ex 1:  to check logged in user is part of the current assigment group and has ITIL role

gs.getUser().isMemberOf(current.assignment_group) && gs.hasRole("itil")

 

ex 2: To write multiple line of code using script include

gs.getUser().isMemberOf(current.assignment_group) && gs.hasRole("itil") && new checkCondition().sampleCode()

 

HemanthM1_0-1724573448216.png

 

script include:

HemanthM1_1-1724573512092.png

 

 

Hope this helps!!!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

4 REPLIES 4

Hemanth M1
Giga Sage
Giga Sage

Hi @Kruthik45 ,

 

Create a UI action as below 

(Make sure you save the form once assignment group is selected to see UI hide/show logic)

HemanthM1_0-1724495916413.png

//Condition
gs.getUser().isMemberOf(current.assignment_group)

//script
current.assigned_to = gs.getUserID(); //set logged in user has assigned to
current.update(); //update

 

Hope this help!!!

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Kruthik45
Tera Contributor

Hi @Hemanth M1 ,

 

Unlike this case, what if I had to write multiple lines of code in the condition section? Can I write my conditions in the script section? Or is it only used for specifying click actions?

 

Thank you,

Pavan

Hi @Kruthik45 

 

Condition section is only to control button visibility (hide/show)

if you want to write multiple line then use &&, || conndition , if its multiple condition and does fit in the condition section use script include and call it from condition section

 

ex 1:  to check logged in user is part of the current assigment group and has ITIL role

gs.getUser().isMemberOf(current.assignment_group) && gs.hasRole("itil")

 

ex 2: To write multiple line of code using script include

gs.getUser().isMemberOf(current.assignment_group) && gs.hasRole("itil") && new checkCondition().sampleCode()

 

HemanthM1_0-1724573448216.png

 

script include:

HemanthM1_1-1724573512092.png

 

 

Hope this helps!!!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Kruthik45
Tera Contributor

Hi @Hemanth M1 ,

 

Thank you. Unlike in this case, what if I had to write multiple lines of code for a condition, not just a single line? Can I use the script section to specify my condition, or is it only exclusive to specifying click actions?

 

Thank You,

Pavan