UI Macro to populate CI field

Russ T
Kilo Guru

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

1 ACCEPTED SOLUTION

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>



find_real_file.png


View solution in original post

15 REPLIES 15

Hi, I am working on same query. After populating CI in configuration item field, then I need to set category field as 'software'. If not selected then it should be in previous value only. Could someone please help me on this?

Hello Dominik, we applied this same UI Macro in our instance and see some inconsistency.
When we click on the button to show the assets, it pops the window but shows no data in the new window. It only works when we click on filter button "All"  on the popOpen window or any of the Column Context Menu. Do you have any idea what we could try to debug this unexpected behavior?
We checked the URL. It builds the correct query to search the CMDB_CI table but doesn't show the result immediately with the pop open window. To make it work we have to click on "All" or the Column Context Menu.
Any lead to debug would be appreciated!
Thanks in advance!

 

Hello Dominik,

 

We applied this same UI Macro in our instance but we see inconsistency. It pops open the window from the cmdb_ci table but doesn't show the assets of the user in first click. To make it work we have to click on "All" or one of the column context menus. We checked if its building the correct query with the parameters passed and it is. However it doesn't pull the info when button is clicked. Do you know any debugging steps we can try to check what could be the cause?

ysrael1
Tera Contributor

Hi, can you share how you managed to place the UI Macro next to the Configuration Item field? I can't manage to make my UI macro appear next to the CI field. Thanks

Right click on the Configuration Item field and click on Configure Dictionary. Then add the name of your UI Macro like shown below. If you have more than one, then separate them with semicolon.
Example:
ref_contributions=task_show_ci_map;show_related_records

Vikas1_0-1689063815261.png