Why am I still seeing duplicated on my reference field

Alon Grod
Tera Expert


Im trying to remove duplicated using ref qualifier and script include but after execution Im not getting any values at all.
What am I doing wrong?

 

Screenshot 2023-07-17 at 20.01.17.png

 

Screenshot 2023-07-17 at 20.01.52.png

Screenshot 2023-07-17 at 20.02.20.png

Screenshot 2023-07-17 at 20.04.32.png

Outcome: 

Screenshot 2023-07-17 at 20.05.49.png

1 ACCEPTED SOLUTION

SaiVasanth
Tera Guru

Hi @Alon Grod ,

-If you don't have that site field should be of reference type it is best to go with lookup select box which is the best option for your requirement.

-Add the u_sites table under type specification and lookup value filed as name and if you want you can give the lookup label field(s) as name,location.

-Important one should be check the unique values only check box

 

Thanks

Accept as solution if it works for you

View solution in original post

3 REPLIES 3

SaiVasanth
Tera Guru

Hi @Alon Grod ,

-If you don't have that site field should be of reference type it is best to go with lookup select box which is the best option for your requirement.

-Add the u_sites table under type specification and lookup value filed as name and if you want you can give the lookup label field(s) as name,location.

-Important one should be check the unique values only check box

 

Thanks

Accept as solution if it works for you

Brad Bowman
Kilo Patron
Kilo Patron

It looks like your sites table has records with non-unique Names.  Your reference qualifier doesn't make sense in that it's passing in the value of u_site which is going to be blank as that is the field the reference qualifier is on, so your Script include is returning the unique records in an empty array.  To only show records with a unique name, use your reference qualifier without current.u_site.  Your Script Include then needs to query the sites table, pushing each result to the resulting array only if the name is not the same as the previous record, so it would look something like this, assuming your table name is 'u_sites' and the name field is 'name':

var UniqueSites = Class.create();
UniqueSites.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	isUnique: function(){
		var storeArr = [];
		var storeName = '';
		var storeGR = new GlideRecord('u_sites');
		storeGR.orderBy('name');
		storeGR.query();
		while (storeGR.next()) {
			if (storeGR.name != storeName){
				storeArr.push(storeGR.sys_id.toString());
				storeName = storeGR.name;
			}
		}
		return 'sys_idIN' + storeArr.join(',');
		
	},
    type: 'UniqueSites'
});

 

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Alon Grod 

Greetings!

try 

site = [];

site.push(sites.getValue("sys_id"))  //passing into array

or 

site.push(sites.sys_id.toString()) ;

 

and get the unique value on site array

 

please mark the answer as correct and helpful based on Impact.

 

Kind Regards,

Ravi Chandra