Best practice of using addEncodedQuery

String
Kilo Sage

Hi Team,

I'm using the below addEncodedQuery but am facing syntax error .Am trying to fetch in wrong way ?

Please guide me 

 

 

var test='99894226';

var test1='TESTING';

var fieldMappingRef = new GlideRecord('asset');
fieldMappingRef.addEncodedQuery(asset_tagSTARTSWITH+'test'+^account.nameSTARTSWITH+'test1');

fieldMappingRef.query();

while (fieldMappingRef.next()) {
gs.info("enter"+fieldMappingRef.getUniqueValue());
}

1 ACCEPTED SOLUTION

Anup Desai1
Mega Sage

Try this

 

var test='99894226';
var test1='TESTING';
var fieldMappingRef = new GlideRecord('asset');
fieldMappingRef.addEncodedQuery('asset_tagSTARTSWITH'+test+'^account.nameSTARTSWITH'+test1);
fieldMappingRef.query();
while (fieldMappingRef.next()) {
gs.info("enter"+fieldMappingRef.getUniqueValue());
}

View solution in original post

3 REPLIES 3

4b0d3
Giga Guru

Easy way is to set it up in the list view.  Right click the query at the top of the list, copy the query.   Paste it into your Encoded query.  What you have is fine.  If you want to do some trickier stuff, look up RLQuery, you can generate this by creating a report and using the SN Utils chrome extension to avoid having to save the report.

Anup Desai1
Mega Sage

Try this

 

var test='99894226';
var test1='TESTING';
var fieldMappingRef = new GlideRecord('asset');
fieldMappingRef.addEncodedQuery('asset_tagSTARTSWITH'+test+'^account.nameSTARTSWITH'+test1);
fieldMappingRef.query();
while (fieldMappingRef.next()) {
gs.info("enter"+fieldMappingRef.getUniqueValue());
}

Kirby R
Kilo Sage

addEncodedQuery accepts string as parameter. So in your query, you need to enclose it in ' ' and it would look like this 

'asset_tagSTARTSWITH' + test + '^account.nameSTARTSWITH' + test1.

 

Your original query treats asset_tagSTARTSWITH as a variable name instead of a string. hope this helps.