- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 08:48 PM
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());
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 09:00 PM
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());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 08:54 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 09:00 PM
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());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 09:02 PM
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.