
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 08:21 AM
Hello everyone,
I am trying to create a UI Macro, which when clicked opens a window showing the list of Configuration Items assigned to the user in the Caller field. When clicking on the CI, this would then populate the CI field on the incident form. I wish to place the button next to the CI field itself (as the Caller field already has three buttons next to it).
I have gotten so far - I have the Macro button appearing where I want, and I have figured out that I need to use reflistOpenUrl and popOpenStandard functions. However I am struggling with creating the filter. I need the Macro to reference the caller field on the incident form, and then filter the CIs displayed in the pop-out window to only show those assigned to that caller - and this is where I am struggling.
If anyone could give me any pointers on how to do that, I'd be grateful. I am new to jelly and hardly a wizard in JavaScript (though I am learning fast!). I have found some older solutions but they are in some cases 8 or 9 years old and no longer seem to work in the same way.
Thanks in advance for any help.
Russ
Solved! Go to Solution.
- 4,502 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 10:06 AM
Thank you so much for your help Patrick. Using that info I now have the button working exactly how I need it! Here is the finished code for future searchers as what I posted before didn't construct the filter URL correctly, screenshot also provided below (clicking the CI in the popup window populates the CI field).
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j2:set var="jvar_n" value="getUserAssets_${ref}"/>
<a id="${jvar_n}" onClick="getUserAssets()" title="Lookup user assets" alt="Add me" tabindex="0" class="btn btn-default icon-hardware"></a>
<script>
function getUserAssets() {
var refurl = reflistOpenUrl('incident.cmdb_ci', 'incident.cmdb_ci', 'cmdb_ci', 'cmdb_ci', 'null', 'false', '');
var url = 'assigned_to=' + g_form.getValue('caller_id');
var refurlquery = refurl + url;
popupOpenStandard(refurlquery, 'lookup');
}
</script>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 09:03 AM
Are you wanting to just provide a prompt for what devices they have, OR limit their selections in the CI field to those CIs assigned to the caller? If you want to limit their selections, you can easily do this with a reference qualifier (e.g. CI assigned to = current.caller_id), and provide the same effect as what you are asking for.
I know there are ways to show lists from a UI macro, but I haven't seen one that pulls the value and then saves it back to the field like the reference field selections do.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 09:20 AM
Hi Patrick
I do want to limit the selection, but only when they click my custom button. I want the usual lookup (magnifying glass) icon to behave as it does today (i.e. show everything as per our current rules).
The reason is, we want a quick way for the service desk to select a user's asset (e.g. BlackBerry) when appropriate, but still be able to select from a full list of CIs when necessary.
The reflistOpenUrl is providing the functionality to populate the field. The difficulty I'm having is in obtaining the caller_id from the Macro and then using this to filter the list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 09:25 AM
Here's the code I have working so far, which provides the button, I click it and the CMDB items are shown, then when I click a CMDB item it populates the field.
I just need to get this code referencing the caller_id field on the incident form, then filter the list shown to only show the assets where caller_id = assigned_to.
The code is hacked from various sources so it's not great.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j2:set var="jvar_n" value="getUserAssets_${ref}"/>
<a id="${jvar_n}" onClick="getUserAssets('${jvar_n}')" title="Lookup user assets" alt="Add me" tabindex="0" class="btn btn-default icon-hardware"></a>
<script>
function getUserAssets(reference) {
;
var refurl = reflistOpenUrl('incident.cmdb_ci', 'incident.cmdb_ci', 'cmdb_ci', 'cmdb_ci', 'null', 'false', '');
var url = 'sysparm_query=assigned_to=' + reference;
var refurlquery = refurl + url;
popupOpenStandard(refurlquery, 'lookup');
// alert(referenceField);
}
</script>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 09:48 AM
You can actually use g_form methods in this macro, which is how you're going to get the caller_id value. Try something like this:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j2:set var="jvar_n" value="getUserAssets_${ref}"/>
<a id="${jvar_n}" onClick="getUserAssets('${jvar_n}')" title="Lookup user assets" alt="Add me" tabindex="0" class="btn btn-default icon-hardware"></a>
<script>
function getUserAssets() {
var refurl = reflistOpenUrl('incident.cmdb_ci', 'incident.cmdb_ci', 'cmdb_ci', 'cmdb_ci', 'null', 'false', '');
var url = 'sysparm_query=assigned_to=' + g_form.getValue('caller_id');
g_form.addInfoMessage('user is: ' + g_form.getValue('caller_id'));
var refurlquery = refurl + url;
popupOpenStandard(refurlquery, 'lookup');
}
</script>
</j:jelly>