Filter the values in reference qualifiers in custom HTML UI page

ShyamSharan
Tera Contributor

Hello everyone. 

 

I have a custom UI page which is called through UI Action. The UI page has a couple of reference qualifiers. One of the reference qualifier is Account. Based on the selected account the values in other reference qualifiers should be filtered out. How to achieve this requirement? 

 

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@ShyamSharan 

So you have 2 or more reference fields on UI page and based on 1st you want to filter 2nd or 3rd reference field?

If yes then check this where I shared solution on how to handle this

Change ui reference query 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur. 

 

Unfortunately, the above solution didn't work.  Here's my code snippet. 
HTML Section:

    <g:ui_form>
      <table>
        <tr>
          <td class="nowrap-label">
            <g:form_label><strong>Account:</strong></g:form_label>
          </td>
          <td class="reference-cell">
            <g:ui_reference name="account" id="account" table="customer_account" completer ="AJAXTableCompleter" query="activer=true" onchange="getContact()"/>
          </td>
        </tr>

        <tr>
          <td class="nowrap-label">
            <g:form_label><strong>Contact:</strong></g:form_label>
          </td>
          <td class="reference-cell">
            <g:ui_reference name="contact" id="contact" table="customer_contact" />
          </td>
        </tr>
<g:ui_form>
 
Client Script: 
function getContact(){
    var accountsysID = gel('account').value;
    var contactnames = gel('contact').value;


    var contactArray = [];

    var gr = new GlideRecord("customer_contact");
    gr.addQuery("account",accountsysID);
    gr.query();

    while(gr.next()){
        contactArray.push(gr.sys_id.toString());
    }

    contactnames.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'contact', 'not', 'cmn_location', '', 'false','QUERY:active=true',           'sys_idIN" + contactArray+ "', '')");

}

 Please tell me if this needs any correction.

@ShyamSharan 

It worked fine for me in the link I shared 8 years ago and have worked fine recently.

seems you have not updated your script as per the logic I shared.

Compare both and make the necessary changes and it should work fine.

HTML Mistake

<g:ui_reference name="account" id="account" table="customer_account" completer ="AJAXTableCompleter" query="active=true" onchange="getContact()"/>

-> 1 mistake is here -> you forgot to add this highlighted in bold

 var contactnames = gel('lookup.contact').value;

-> 1 more here -> the table should be customer_contact and not location

contactnames.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'contact', 'not', 'customer_contact', '', 'false','QUERY:active=true', 'sys_idIN" + contactArray+ "', '')");

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur, I have made the changes and still I am unable to filter out the contacts. 
Please find the updated code below. 

HTML Section:

 <g:ui_form>
      <table>
        <tr>
          <td class="nowrap-label">
            <g:form_label><strong>Account:</strong></g:form_label>
          </td>
          <td class="reference-cell">
            <g:ui_reference name="account" id="account" table="customer_account" completer ="AJAXTableCompleter" query="active=true" onchange="getContact()"/>
          </td>
        </tr>

        <tr>
          <td class="nowrap-label">
            <g:form_label><strong>Contact:</strong></g:form_label>
          </td>
          <td class="reference-cell">
            <g:ui_reference name="contact" id="contact" table="customer_contact" />
          </td>
        </tr>
<g:ui_form>
 
Client Script:
function getContact(){
    var accountsysID = gel('account').value;
    var contactnames = gel('lookup.contact').value;


    var contactArray = [];

    var gr = new GlideRecord("customer_contact");
    gr.addQuery("account",accountsysID);
    gr.query();

    while(gr.next()){
        contactArray.push(gr.sys_id.toString());
    }

    contactnames.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'contact', 'not', 'customer_contact', '', 'false','QUERY:active=true',           'sys_idIN" + contactArray+ "', '')");

}
 
Please let me know if I have to do anymore changes.