
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 03:12 PM
Hi Team,
Hopefully a simple one, but I can't figure out how to code this one. Currently when I press the 'Resolve' UI Action there is automation with a BR that ensures all Children records are updated and also closed.
However - I would like a confirmation message to popup - only if there are active Children, to stay 'This will also resolve the Children, are you sure?' with an 'OK' and 'Cancel'. If 'OK' is selected the 'Resolve' continues as per normal; if 'Cancel' nothing is done.
The OOTB Resolve code is below:
function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.incident_state = IncidentState.RESOLVED;
current.update();
current.resolved_by = gs.getUserID();
}
What I would like to add (I think) is something like this:
var grChild = new GlideRecord("incident");
grChild.addQuery('parent_incident', current.sys_id);
grChild.addActiveQuery();
grChild.query();
if (grChild.getRowCount() > 0) {
<some message function here>('This Incident has children, resolving this Parent record will also resolve all children');
then abort if cancel.
otherwise continue.
But when I add this at the beginning of the 'resolve' script, with a 'gs.addErrorMessage' or 'g_form.showFieldMsg' nothing happens when I click the 'Resolve' button.
Any ideas?
Thanks Carl.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 03:37 PM
Hello Carl,
You can create a display business rule and then store the response value in scratchpad. Now you can use the scratchpad in UI action to validate whether to show alert or not.
https://docs.servicenow.com/bundle/kingston-application-development/page/script/business-rules/concept/c_ScriptingWithDisplayBusinessRules.html
Thanks,
Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 03:37 PM
Hello Carl,
You can create a display business rule and then store the response value in scratchpad. Now you can use the scratchpad in UI action to validate whether to show alert or not.
https://docs.servicenow.com/bundle/kingston-application-development/page/script/business-rules/concept/c_ScriptingWithDisplayBusinessRules.html
Thanks,
Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 04:32 PM
Hi Pradeep,
Thanks for your reply - I'm not a heavy scripter so trying to figure this one out. Code I have now is below, but still not working:
New BR on display, condition, active=true and status not resolved, closed or cancelled.
(function executeRule(current, previous /*null when async*/) {
var grChild = new GlideRecord("incident");
grChild.addQuery('parent_incident', current.sys_id);
grChild.addActiveQuery();
grChild.query();
if (grChild.getRowCount() > 0)
g_scratchpad.childmessage = "anything as it needs to be not null";
})(current, previous);
Updated the Resolve UI Action as below:
function resolveIncident(){
//start of new code
if(g_scratchpad.childmessage != ''){
gs.addErrorMessage('test message');}
//end of new code
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}
But it's still not doing anything. What am I missing here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 09:51 PM
Hello Carl,
gs should not be used at client side i.e gs.addErrorMessage('test message'); Refer to client-side scripts in the link shared below. Let me know if you have any questions.
https://docs.servicenow.com/bundle/kingston-application-development/page/script/general-scripting/reference/r_ScriptingAlertInfoAndErrorMsgs.html
Thanks,
Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 12:22 PM
Hi Pradeep,
Thanks for your help - I have managed to get this to work and also allow the action to be cancelled - adding code here to assist others who might have the same need.
Business Rule code:
(function executeRule(current, previous /*null when async*/) {
var grChild = new GlideRecord("incident");
grChild.addQuery('parent_incident', current.sys_id);
grChild.addActiveQuery();
grChild.query();
if (grChild.getRowCount() > 0) {
g_scratchpad.childmessage = "Yes";
gs.log(g_scratchpad.chilmessage);
}
else
g_scratchpad.childmessage = "No";
gs.log(g_scratchpad.chilmessage);
})(current, previous);
Resolve UI Action code - this was added at the beginning, after the initial function.
if(g_scratchpad.childmessage == 'Yes'){
var answer=confirm("test message");
if (answer==false)
return false;
}
Now it works great.
Cheers Carl.