UI action on a reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 02:39 PM
I'm a newbie learning scripting. I want to add a UI action to a form. This UI action adds a button when a field contains the word Test. The word, Test, is selected from a list of services available to a certain user.
When I add the condition current.u_category != 'Test' in the UI action condition then go to execute the form, the button appears on all the forms before u_category contains anything.
Do I need the clear the field first? What am I not understanding?
MK
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 03:34 PM
current.u_category != 'Test' means u_category is not 'Test' and that includes an empty field. If you want the button to only show up on the forms that have a value 'Test' selected from the u_category options, you should set the Condition to:
current.u_category == 'Test'
If u_category is a reference field, it actually contains the sys_id of the records it is currently referencing and not word "Test". In that case I would suggest: current.u_category.getDisplayValue() == 'Test'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 07:24 PM
Thank you for your response. I actually tried both != and == thinking I misunderstood the syntax. Neither worked. I also tried the version with the getDisplay and i t didn't work.
Perhaps I am misunderstanding how the action is supposed to work. I want to create a new record and when I get down to the category field I want to select 'Test' and immediately have the button become available when that condition is met. I have a script to execute when the button is clicked as well as another script to run to save the record (the one referenced here http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/). But the button either appears once the form is loaded or not at all. Not when the u_category field = 'Test.'
Am I understanding the UI action correctly?
MK

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 09:04 PM
UI Actions run once, when form is loaded. Client UI actions basically provide a way to run whatever code you need client side once the button or link provided by that UI Action is clicked.
What you you are trying to accomplish is going to be a bit advanced and would require DOM manipulation.
I would consider all other possible ways of accomplishing your goal here before doing the above.
What new function would this new button provide the user with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 09:53 PM
I see. Well that explains the form behavior! When 'Test' is selected the button would allow appointments for service to be scheduled but these appointments are only available for that one category.
We can accomplish this in a different way now that I know UI action is not what we want. We can just redirect to the scheduling application after completing the form and clicking save.
Thank you so much for your help!
MK