The CreatorCon Call for Content is officially open! Get started here.

Load related list onChange while creating a new record

Tomko
Tera Expert

I have a feeling I am missing something obvious here...   The use case is specific to the creation of a Call record, but should apply to the creation of any record.

When creating a new Call, as soon as the Caller field is changed, I want to display a related records table with all open Incidents for the caller.

The flow would be:

  1. User Clicks New Call
  2. User enters a valid Caller Name
  3. User tabs or otherwise leaves the Caller Name field
  4. A related list containing all open incidents for the caller appears


I've tried using an onChange client script with the following:

                  GlideList2.get(g_form.getTableName() + '.YOUR_RELATED_LIST_NAME_HERE').setFilterAndRefresh('');

which I found at

        Reload a Form or Related list from a Client Script - ServiceNow Guru

but this doesn't seem to be what I need.   To be clear, I want the list to show before the new record is submitted.

I tried the above with List V3 turned off using "GlideList2" and with List v3 turned on using "GlideListV3".

1 ACCEPTED SOLUTION

Tomko
Tera Expert

I came up with a workaround.   I have a client script that is saving the record on change for the field in question, triggering the related lists to show.




function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '' || oldValue == newValue)


  return;



  g_form.save();



}


View solution in original post

7 REPLIES 7

Abhinay Erra
Giga Sage

I am not sure if GlideList methods are available for client scripts. Usually they are used for context menus and UI actions.


Is there another/better way to accomplish what I am looking for?


LaurentChicoine
Tera Guru

Hi John,



I don't know in which release this was added but in Helsinki on the incident form you have a triangle icon following the caller to allow to see the caller incidents. You can also add this inside Call by adding an attribute to the dictionary of the caller field.



The attribute is: ref_contributions=user_show_incidents



This actually takes all incident including closed ones. "user_show_incidents" is actually a UI Macro. So you could create a custom UI Macro that is a copy from this one and restrict to open incidents (adapted for call as the default one is for incident)



For exemple: UI Macro "user_show_open_incidents_call"



<?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 query = 'caller_id' + '=' + g_form.getValue(reference);


              query += '^' + 'active=true';



              var gdw = new GlideModal('show_list');


              gdw.setTitle(title);


              gdw.setSize(750);


              gdw.setPreference('table', 'incident_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>



Then, simply add the attribute ref_contributions=user_show_open_incidents_call to the caller field on Call.


Thank you.   That is definitely helpful.   My preference is still to show the related list, but this is good as well.