UI Macro button on a field

Maria DeLaCruz
Tera Guru

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.

find_real_file.png

Thanks,
Maria

1 ACCEPTED SOLUTION

Maria DeLaCruz
Tera Guru

After seeking help from our ServiceNow Technical Consultant, the UI macro is now working!



Here's the updated script include:



find_real_file.png



Here's the updated UI macro:



find_real_file.png


View solution in original post

15 REPLIES 15

Maria DeLaCruz
Tera Guru

After seeking help from our ServiceNow Technical Consultant, the UI macro is now working!



Here's the updated script include:



find_real_file.png



Here's the updated UI macro:



find_real_file.png