Check fields complete when UI action selected before running
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 06:17 AM
Hi All,
We have a UI action of 'complete' on our change request form. When this UI action is selected it needs to check the following:
1. Proposed change has been applied
2. if the client communication needed field is ticked (u_client_communication_needed1) and the final communication sent is not blank (u_final_communication_sent)
3. all tasks are completed
If any of the 3 are not true then the process is aborted, the user is shown back to the form with an info message explaining the issue
4 completion code has a value, if not bring up the field in a pop up to be completed.
I've tried to achieve this with the following but it is not doing anything when the UI action is clicked:
Any help is greatly appreciated
function checkproposedchange(){
var pc = new GlideRecord('task_ci');
pc.addQuery('task',current.sys_id);
pc.query();
while (pc.next())
if (pc.applied != true){
gs.addInfoMessage(gs.getMessage('The proposed change must be applied before the change request can be completed'));
}
}
function checkchgtskcreated(){
var chgtsk = new GlideRecord('change_task');
chgtsk.addQuery('change_request',current.sys_id);
chgtsk.addQuery('active',false);
chgtsk.query();
if(!chgtsk.next())
{
gs.addInfoMessage("Please complete all tasks before completing the change request");
current.setAbortAction(true);
}
}
if(current.u_client_communication_needed1 == true && current.u_final_communication_send == ""){
gs.addInfoMessage(gs.getMessage('Client communication needs sending before the change request can be completed'));
}
current.setAbortAction(true);
action.setRedirectURL(current);
function makemandatecomplete()
{
var comp_code= g_form.getValue("u_completion_code");
var comp_notes = g_form.getValue("u_completion_notes");
if (comp_code == "" && comp_notes == "")
{
var gdw = new GlideDialogWindow('u_change_complete');
gdw.setTitle('PIR Details');
gdw.setSize(400,300);
gdw.setPreference('client_comm' , g_form.getValue('u_client_communication_needed1'));
gdw.render();
}
else{
g_form.setMandatory('work_end',true);
g_form.setMandatory('u_completion_code',true);
g_form.setMandatory('u_completion_notes',true);
gsftSubmit(null, g_form.getFormElement(), 'complete');
}
}
if(typeof window == 'undefined')
runcode();
function runcode()
{
current.state = '6';
//current.setWorkflow(false);
current.u_completion_time = gs.nowDateTime();
current.update();
action.setRedirectURL(current);
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 06:23 AM
Hi Sam,
Quick question before I dive in to this... Would it make more sense, from a user experience, to not even show that button until the criteria you mentioned are fulfilled? Why allow someone to smack a button only to get yelled at?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 06:31 AM
Hi Chuck,
Thanks for the above question. I appreciate your point and we did think of this as well, but usually it is our change manager that completes the change and knows what needs to be checked before. We have had the issue where someone filling in while they were off completed the change without checking all the points mentioned. We decided that if the complete button did not appear the person filling in would not know what needed to be checked before the button appeared so instead wanted the button to appear, but if they selected it before checking all the relevant information a prompt would appear so they knew exactly what they should be checking.
Hope this makes sense, but appreciate if you have other suggestions on this.
Thanks
Sam

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 06:38 AM
Here's my strategy... move all the related record checks to a script include.
"Did you apply all proposed changes? and Are all the tasks completed?" Those are easy functions to test outside the UI action - script includes are great for this. Watch episode 6 of TechNow if you want some more information on that.
Use those in your condition statement. If those conditions aren't complete, don't put the button on the form, is what it should do. That way the button IS available when they are despite having to still finish up a couple things on the form.
The client script part can check if those are done and give a warning if not, otherwise the server side component of the UI action processes as it should. This article should help you construct the script part of the UI action once you get the script include done that drives the condition.
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 07:12 AM
Hi Chuck,
Thanks for the above, I will try and look into this. So will this still give me the same outcome of the 'complete' UI action appearing on the form and then if the user selects this but not all the criteria is complete an info message will appear?
Thanks