- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2016 02:13 PM
Hello,
I have a UI action that I want to convert to a UI Macro so that I can add it as a button at the end of a field.
Here's my UI action:
var onCall = new MHSOnCall("SMS",current.u_other_on_call_group_1);
var user = onCall.getPrimaryUserByGroup();
if (user) {
var wf = new Workflow();
var wfId = wf.getWorkflowFromName("MHS On-Call Voice");
// add as many variables as your workflow is expecting, then pass the object
gs.log ("Workflow ID "+wfId);
var vars = {};
vars.assignment_group = current.u_other_on_call_group_1;
gs.log ("assignment_group in vars "+vars.assignment_group);
gs.log ("vars [Object] "+vars);
wf.startFlow(wfId, current, current.operation(),vars);
action.setRedirectURL(current);
}
else {
gs.addInfoMessage("Assignment Group doesn't have either on-call schedule or Primary On-Call ");
action.setRedirectURL(current);
}
Here's what I've tried on the UI macro, but it's not working:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="callOnCallGroup1_${ref}"/>
<a id="${jvar_n}" onclick="callOnCallGroup1('${ref}')" title="${gs.getMessage('Call On-Call Group 1')}" tabindex="0" class="icon ref-button icon-phone btn btn-default btn-ref"></a>
<script>
function callOnCallGroup1(reference){
var onCallgroup = g_form.getValue(reference.split('.')[1]);
var onCall = new MHSOnCall("SMS", onCallgroup);
var user = onCall.getPrimaryUserByGroup();
if (user) {
var wf = new Workflow();
var wfId = wf.getWorkflowFromName("MHS On-Call Voice");
// add as many variables as your workflow is expecting, then pass the object
gs.log ("Workflow ID "+wfId);
var vars = {};
vars.assignment_group = onCallgroup;
gs.log ("assignment_group in vars "+vars.assignment_group);
gs.log ("vars [Object] "+vars);
wf.startFlow(wfId, current, current.operation(),vars);
action.setRedirectURL(current);
}
else {
gs.addInfoMessage("Assignment Group doesn't have either on-call schedule or Primary On-Call ");
action.setRedirectURL(current);
}
}
</script>
</j:jelly>
The button shows on the field, but when I click it, nothing happens. Please help.
Thanks,
Maria
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2016 08:49 AM
After seeking help from our ServiceNow Technical Consultant, the UI macro is now working!
Here's the updated script include:
Here's the updated UI macro:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 01:34 PM
Hi Maria,
In the Script Include I posted, we only log the message "Assignment Group doesn't have either on-call schedule or Primary On-Call" if the MHSOnCall getPrimaryUserByGroup method did not return a user, or if the incident that is being looked-up doesn't exist.
At the time the UI Macro is clicked, has the Incident been submitted? By that, I mean is this an existing Incident, and you are clicking on the macro after loading the form? Or is it a New incident which hasn't been saved yet? The script above works only if the incident already exists.
It would be worthwhile to log what is returned by getPrimaryUserByGroup and whether the GlideRecord get operation succeeded. I have slightly modified the function to add that logging capability:
callGroupOne: function() {
var debug = this.getParameter("sysparm_debug");
var group1 = this.getParameter("sysparm_other_group");
var sys_id = this.getParameter("sysparm_sys_id");
var current = new GlideRecord("incident");
var gotIncident = current.get(sys_id);
var onCall = new MHSOnCall("SMS", group1);
var user = onCall.getPrimaryUserByGroup();
gs.log("Did we get our incident? " + gotIncident);
gs.log("Did we get our user? " + typeof user);
if (user && gotIncident) {
var wf = new Workflow();
var wfId = wf.getWorkflowFromName("MHS On-Call Voice");
var vars = {};
vars.assignment_group = group1;
if (debug == "true") {
gs.log("Workflow ID " + wfId);
gs.log ("assignment_group in vars " + vars.assignment_group);
gs.log ("vars [Object] "+ new JSON().encode(vars));
}
wf.startFlow(wfId, current, "update", vars);
return "Workflow started.";
} else {
gs.log("Assignment Group doesn't have either on-call schedule or Primary On-Call ");
return;
}
},
When you make the changes to your Scipt Include and try again, what do the log messages say?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2016 08:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2016 11:58 AM
Hi Maria,
Great! That means that we aren't getting the Incident record.
Let's change the client-side code. There is a line that attempts to get the record's sys_id:
ga.addParam("sysparm_sys_id", g_form.getValue("sys_id"));
Let's change that:
ga.addParam("sysparm_sys_id", g_form.getUniqueValue());
Also, on the Script Include, let's add a log line for the sys_id (after we get the value from sysparm_sys_id):
gs.log("The sys_id is: " + sys_id);
That way, we will know that the sys_id got passed up correctly.
I have a feeling that this will solve the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2016 02:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2016 03:29 PM
Hi Maria,
That is telling us that the vars object wasn't passed in to the workflow properly, or it's not being referenced properly. That's odd, because lines 18 and 19 of the function I posted earlier specifically set up the vars object, give it the assignment group key, and the sys_id of the assignment group for that key.
Can you post the content of your Script Include, and the content of that "If" activity from your workflow?