ui macro and current record information

poyntzj
Kilo Sage

Thursday afternoon before a long weekend and I'd said I'd look at something for a colleague and now I regret it

We need to show the information from a "source" record, but the usual dot walking is doing some very odd things.- hi ticket logged

I said, "use something like a summarizer and do it yourself via a ui macro"

Well, in principle it is dead easy, but for some reason I am struggling to get the details of the current record across

In the "approval_summarizer_sc_request", there are the following lines

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="true" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

      <tr>

              <td class="label_left" width="100%">

                      ${gs.getMessage('Summary of Request being approved')}:

                     

                      <g:label_spacing/>                              

              </td>

      </tr>

      <g:evaluate var="jvar_total" expression="      

              var sc_request = ${ref}.sysapproval;

gs.log(sc_request);

when I look at an approval for a request, I see an entry in the log for the sys_id

From there it is dead easy to carry on and do what we need -we know as we have updated a couple of these.

I called this a new name and inserted it as a new ui macro

I have made a formatter linking to this new ui macro

I run it I see the text on the screen, but nothing in the log to show me the value from the field

(If I remove lines 12/13 I do see "are you there" in the logs

The code is

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="true" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

      <tr>

              <td class="label_left" width="100%">

                      ${gs.getMessage('Summary of tpip being approved')}:

                      <g:label_spacing/>                              

              </td>

      </tr>

      <g:evaluate var="jvar_total" expression="      

gs.log('are you there ?');

              var sc_request = ${ref}.u_inherited_tpip_request;

gs.log(sc_request);

So my questions are

1.   How do I pass the current record information to the script - If get this current ID I can get the field value I need

2.   Better still,. how I do pass the value from the u_inherited_tpip_request

There is scarce info about ui_macro's and on the pages I do see for Jelly etc I do not see any real reference to ${ref}, but the examples do use it

Cheers

5 REPLIES 5

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Look at the approval_summarizer macro. That calls other macros based on attributes of the approval record, either table or the table of the sysapproval reference. You likely need to rename your macro to follow suite.  



The table I am looking to work on is a new table that the other project has created.


All it needs to do is if a field has a record number show the summary of that linked record - dot walking is doing some really odd things and a HI ticket has been raised



I created a formatter calling the "approval_summarizers_sc_request" directly on an approval record and it did not work.


I then called the "approval_summarizer" and still failed


That made me think that the "approval_summarizer_master" was involved.



However, if you look at something like these


Adding a UI Macro (button) to Any Field with Fuji Icons


Formatter - UI amcro placed on incident form - need to hide it , how?



you will see they are using the ${ref}


I thought based off those there maybe a ref_contributions that was doing the magic, but when I looked at that, it was not


(I have used the above when I was looking at one of the methods of using a slushbucket on the table / form)



The problem with the above two examples is that they are reliant on the onClick.   I need to show the summary of the linked record as the form loads



If I can just get the link working between this field and the macro / fomatter I am off and running.   just seems to elude me at the moment


I'm not sure if you found the solution to this issue but I've ran into the same problem (creating a custom ui macro, put into a new ui formatter, and putting it on a custom form). If I use the following


${ref_parent}


It will display the table.



But if I loop through and output with stringify:


<g:evaluate jelly='true'>


  var id = JSON.stringify(${ref_parent});


</g:evaluate>


${id}



Part of the object:


{"sys_class_name":{},"sys_created_by":{},"sys_created_on":{},"sys_id":{},"sys_meta":{"active":"1","array":"0","attributes":"u_conference_room=true,



I get the full object output. Conference room oddly enough is actually a reference field and returns true. However, most of the properties of the object are empty, including the sys_id (yes I'm running this on an existing record). I feel like i've gone through all the OOB UI Macros and still can't understand why I can't access the current record information. I wonder if it has something to do with the UI Formatter.


The original issue is still an open ticket with ServiceNow


All the ui macro / summarizer does is calls the relevant record and then info we need



<?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_source_tpip" value="$[current.getValue('u_inherited_tpip_request')]" />



      <g2:evaluate var="jvar_utrgr" object="true" jelly="true">      


              var utrgr = new GlideRecord('u_tpip_request');      


              utrgr.addQuery('sys_id', jelly.jvar_source_tpip);      


              utrgr.query();      


              utrgr;      


      </g2:evaluate>      



      <j2:while test="$[jvar_utrgr.next()]">      


              <table>


                              <tr>


                                      <td class="label_left" width="15%">


<g:label_spacing/>


                                      Number :


                              </td>


                             


                                      <td> <span style="white-space:pre-line">


                                              $[jvar_utrgr.getValue('number')]


                                              </span>


                                      </td>


                                     


                             


                      </tr>


                      <tr>


                              <td class="label_left">


<g:label_spacing/>


                                      Department :


                              </td>


                              <td> <span style="white-space:pre-line">


                                      $[jvar_utrgr.getValue('u_esm_function')]


                                      </span>


                              </td>


                      </tr>


                      <tr>


                              <td class="label_left">


<g:label_spacing/>


                                      Product Name :


                              </td>


                              <td> <span style="white-space:pre-line">


                                      $[jvar_utrgr.getDisplayValue('u_product_name')]


                                      </span></td>


                              </tr>


                      <tr>


                              <td class="label_left">


<g:label_spacing/>


                                      TPIP Name :


                              </td>


                              <td> <span style="white-space:pre-line">


                                      $[jvar_utrgr.getDisplayValue('u_third_party')]


                                      </span></td>


                              </tr>


                      <tr>


                              <td class="label_left">


<g:label_spacing/>


                                      License Name :


                              </td>


                              <td> <span style="white-space:pre-line">


                                      $[jvar_utrgr.getDisplayValue('u_name_of_license')]


                                      </span></td>


                              </tr>


                      <tr>


                              <td class="label_left">


<g:label_spacing/>


                                      Use Case :


                              </td>


                              <td> <span style="white-space:pre-line">


                                      $[jvar_utrgr.getValue('u_proposal_software')]


                                      </span></td>


                              </tr>


              </table>



      </j2:while>



</j:jelly>