Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to display related records with UI Macro like in Incident form

Armin Heinlein1
Giga Expert

Hi,

I am still trying to improve my very first scoped application and would like to show related records for a member. Same way how it is done in the incident form. So I created the reference contribution to the table that contains the records I want to display. Member is a referenced field to the member table.

find_real_file.png

find_real_file.png

Then I created a UI Macro called member_show_requests. Yes, I copied the user_show_incidents UI macro because I thought it is a similar request.

But I guess I tried to make my life too easy. It is not working.

What am I missing?

I spend a lot of time trying to get this to work but don't know where to look.

--------------------------------------------------------------

<?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="show_my_records_table_${jvar_guid}:${ref}"/>

<g:reference_decoration id="${jvar_n}" field="${ref}"

            onclick="showRelatedList('${ref}'); "

            title="${gs.getMessage('Show related records')}" image="images/icons/tasks.gifx"/>

<script>

// show related list

function showRelatedList(reference) {

            try {

                      var displayValue = g_form.getDisplayBox(reference).value;

                      var title = 'Showing records related to: ' + displayValue;

                      var s = reference.split('.');

                      var referenceField = s[s.length - 1];

                      var query = referenceField + '=' + g_form.getValue(reference);

                      var gdw = new GlideModal('show_list');

                      gdw.setTitle(title);

                      gdw.setSize(750);

                      gdw.setPreference('table', 'my_records_list');

                      gdw.setPreference('sysparm_query', query);

                      gdw.setPreference('title', 'Related records');

                      gdw.render();

            } catch (e) {

                      jslog('error showing related list');

                      jslog(e);

            }

}

</script>

</j:jelly>

8 REPLIES 8

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

What is the name of your table?   You called it the 'member' table, but the code suggest it is my_records (based on my_records_list).   I'm guessing since it is a custom table it is not actually my_records but is probably something like u_member.   In which case the table reference should be 'u_member_list'.


Hi Joe,



Thank you for getting back to me.



Maybe I should describe my scenario:



I have a table HIPAA requests "x_conym_hipaa_req_hipaa_insurance_record_requests" and I have a table member "x_conym_hipaa_req_member". When I go to the form that maintains the HIPAA requests I would like to show what other HIPAA requests the member has filed. Just like in Incidents. What do I do wrong or what am I missing.



This is what I have done so far:



  1. I set up the attribute for the member in HIPAA table "x_conym_hipaa_req_hipaa_insurance_record_requests"
    find_real_file.png
  2. I created a UI Macro called "member_show_requests" and I changed it based on your question

    find_real_file.png
  3. Shouldn't I be seeing the tasks icon next to the member in my HIPAA form. Yes, the member has another record in the HIPAA table?
    find_real_file.png


  4. Just to show the record in the member table "x_conym_hipaa_req_member".
    find_real_file.png

This worked for me for a custom scope and table (x_snc_jdmtestapp_test_app) and a custom ui macro (x_snc_jdmtestapp_member_show_requests) based on the user_show_incidents macro.   Make sure you use the fully qualified scope name for the macro in the dictionary entry.   Below is the macro and my results.



<?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="show_incidents_${jvar_guid}:${ref}"/>


<g:reference_decoration id="${jvar_n}" field="${ref}"


  onclick="showRelatedList('${ref}'); "


  title="${gs.getMessage('Show related incidents')}" image="images/icons/tasks.gifx"/>




<script>


// show related list


function showRelatedList(reference) {


  try {


  var displayValue = g_form.getDisplayBox(reference).value;


  var title = 'Showing records related to: ' + displayValue;


  var s = reference.split('.');


  var referenceField = s[s.length - 1];


  var query = referenceField + '=' + g_form.getValue(reference);




  var gdw = new GlideModal('show_list');


  gdw.setTitle(title);


  gdw.setSize(750);


  gdw.setPreference('table', 'x_snc_jdmtestapp_test_app_list');


  gdw.setPreference('sysparm_query', query);


  gdw.setPreference('title', 'A New Title');


  gdw.render();


  } catch (e) {


  jslog('error showing related list');


  jslog(e);


  }


}




</script>


</j:jelly>



Screen Shot 2017-03-29 at 8.08.17 AM.png


Screen Shot 2017-03-29 at 8.02.50 AM.png


Hi Joe,



Did not work for me.



Ok, I did what you said. No Task icon next to the member?????


I cannot even run it. Is it correct the only entry you changed in your UI Macro was the one for the table?


Do I have to do something with System Properties.


I remember I had to add some entries before I could color the button or customize the list for activities.



The UI Macro


find_real_file.png


The dictionary entry for the member


find_real_file.png