Distinct or unique values on reference field / lookup

Nik Amy
Tera Contributor

Hey all

On a form i have created a reference field which points to a custom table and this table has NO UNIQUE key.

So upon clicking the lookup icon, it should display only unique or distinct values like below it should show only 1200 and 1300.

 

      VenIDName
1200ABC
1300XYZ
1200JKL

I have made use of reference qualifier and wrote a code like

vendorIdList = arrayUtil.unique(vendorIdList);

This is working, but since the table has some thousands of records, its taking very long time to display the unique values.

Any other method to achieve this quickly.

TIA

17 REPLIES 17

Hi Nikh,



I understand. I will recommend you give it a try to see how it goes . i don't think performance will be an issue and you can go through the elements by typing the name of the element you will like.



As for the reference field, be aware at the end your selection will be associated to a specific record of the table you're referencing. This could lead into confusion or issues either for your end users or your developers.



Thanks,


Berny


Slava Savitsky
Giga Sage

For reference and select box variables in Service Catalog, this can be achieved by ticking Unique values only checkbox in the variable definition. Strangely, there is no similar option for normal reference fields.


Kalaiarasan Pus
Giga Sage

That is where GlideAggregate comes in handy. Always use it while getting distinct value.



Getting Distinct Records | GarrettNow


Distinct GlideRecord Query - ServiceNow Guru  


Hey kalai



Its working in background scrips, but same way when i did with script include, its not working


its not returning any values at all.



I wrote the code like:



var ticket_id= [];


  var ticket_list = new GlideAggregate('u_venn');


  ticket_list.groupBy('u_ven_id);


  ticket_list.query();


  while(ticket_list.next())


  {


  ticket_id.push(ticket_list.sys_id+'');


  }


  if(ticket_id.length>0)


  {


  return 'sys_idIN'+ticket_id+'';


  }


  else


  {


  return 'sys_idIN'+'***'; //


  }



BR


Nikh


Hi Nikh,



You may want to check if your script include is "client callable".



Thanks,


Berny