Related List and Relationship Script

Tarasingh26
Tera Expert

Hi All,

 

I have created related list relationship which is working fine but it shows all records. It should show only filtered records. Below is Script I have written, where could be issue why filter is not working in this case? My requirement is to use GlideRecord.

 

(function refineQuery(current, parent)
{

var trendword=parent.getValue('u_trendword');
var leArray=[];
var gr = new GlideRecors(sn_risk_advanced_event);
gr.addEncodedQuery('nameLIKE +trendword);
gr.query();
while(gr.next())
{
leArray.push(gr.getValue('number'));
}

current.addQuery('number','IN',leArray);
})(current,parent);

4 REPLIES 4

Hemant Goldar
Mega Sage
Mega Sage

Hi @Tarasingh26 ,

Change GlideRecors-> GlideRecord.

 

I hope this helps!

 

Regards,

Hemant 

**Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.**

This is typo from my side. but in instance it is correct.

You should copy/paste what you have in the actual script to make this easier.  The name of the table should be in quotes on that same line.  And the "addEncodedQuery" line is not terminated with a single quote.  Should be "gr.addEncodedQuery('nameLIKE' + trendword);".  It's hard to debug something that is not accurate to begin with.

 

You might also want to take a look at these 2 posts for future questions:

TNT: Screenshots Help, but Code is Better

TNT: And Formatted Code is Even Better

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Tarasingh26 

It would be easier when you share screenshots so that we get to know it's applied on which table etc

try this

(function refineQuery(current, parent){
	
	var leArray = [];
	var gr = new GlideRecors('sn_risk_advanced_event');
	gr.addEncodedQuery('nameLIKE' + parent.getValue('u_trendword'));
	gr.query();
	while(gr.next())
	{
		leArray.push(gr.getValue('number'));
	}
	current.addQuery('number','IN',leArray);
	
})(current,parent);

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