- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 03:30 PM
I have been racking my brains out, how to create a UI Action, and have it set the work notes to mandatory A UI Policy will set it, but the state will have been updated by then. Not much use. I have been trying to use the article listed here, such as this one:
https://community.servicenow.com/thread/199189?q=cancel%20ui%20action%20mandatory
This is what I have based on the above link, almost verbatim, but when I hit the Button, nothing happens, no warning, no redirect, nothing. All I am trying to do is get the work notes to be mandatory, show a warning. and abort the UI action if there are none.
Many thanks, if I find a way I will post it here. Cheers, Mark S
Script |
---|
function cancelTask(){ if(g_form.getValue('work_notes') == ''){ g_form.hideFieldMsg('work_notes'); g_form.setMandatory('work_notes', true); g_form.showFieldMsg('work_notes','NOTES are mandatory when cancelling a change task.','error'); return false; //Abort submission }else { //do not enforce mandatory fields. gsftSubmit(null, g_form.getFormElement(), 'cancelTask'); //MUST call the 'Action name' } } if(typeof window == 'undefined') { cancelTsk(); } function cancelTsk(){ current.state=4; new Workflow().cancel(current); gs.addInfoMessage('You messed up!'); action.setRedirectURL(current); current.update(); action.setRedirectURL(current); } |
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 03:35 PM
You are missing an "onclick" field in your UI Action form. when you click the "Client" checkbox, it is supposed to show that. You will need to make sure you get that added to your form, or figure out which UI Policy isn't working that is not showing that field. then you can add "cancelTask();" to that field once you get it to show up.
Or, you can edit the onclick field from your list view of UI Actions and enter the text above. That will tell it to call that function when clicked. I haven't looked at the rest of your code yet, but try that to see if it helps.
Not sure if it will conflict, but just in case, you may want to make your "action" name different than the client side function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 05:34 PM
Thanks for the reply, looks like Jonathan Barnes' reply above did the trick. I will be posting the full context for a Cancel UI, along with a Business Rule to check for open tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 10:24 PM
You might also consider using a "u_" prefix in both the Action name and the function name in case ServiceNow creates a UI Action with the same Action name or there's already a function with that name (or in the future). I tend to use the "u_" prefix everywhere just in case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 08:22 AM
Thanks for looking Jim, always appreciate your contributions. Mark S.