- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 01:27 AM
when I add conditions in platform I get this for query:
short_descriptionSTARTSWITHTest
^NQsys_tags.b112ee371bd5c2101ff2dc6a9b4bcb89=b112ee371bd5c2101ff2dc6a9b4bcb89
^sys_tags.b635774d1bed0a101ff2dc6a9b4bcbd4=b635774d1bed0a101ff2dc6a9b4bcbd4
it returns 2 records, one where short description starts with Test and the other one which has to tags assigned.
i'd like to find the same two records with script, but as you can imagine: dynamically. I do NOT want to use the query from platform as for addEncodedQuery
i'd like to be able to "build" the query the same way.
I am going nuts here, once more.
I can find either one or the other record by using
either:
or:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 01:44 AM
Hi @MichaelZischeck
Conceptual script to use direct addencodedquery
var grKnow = new GlideRecord('your_table_name');
// Start the first query
grKnow.addQuery('short_description', 'STARTSWITH', 'Test');
// Since we cannot directly chain ‘NQ’, we execute and store these records
var matchingRecords = [];
grKnow.query();
while (grKnow.next()) {
matchingRecords.push(grKnow.getUniqueValue());
}
// Begin a new query for the tag conditions
var grKnowTags = new GlideRecord('your_table_name');
grKnowTags.addQuery('sys_tags.b112ee371bd5c2101ff2dc6a9b4bcb89', 'b112ee371bd5c2101ff2dc6a9b4bcb89');
grKnowTags.addQuery('sys_tags.b635774d1bed0a101ff2dc6a9b4bcbd4', 'b635774d1bed0a101ff2dc6a9b4bcbd4');
grKnowTags.query();
while (grKnowTags.next()) {
var uniqueId = grKnowTags.getUniqueValue();
if (!matchingRecords.includes(uniqueId)) {
matchingRecords.push(uniqueId);
}
}
// At this point, ‘matchingRecords’ contains the unique ID of all records matching either condition set.
// To perform operations on these records, iterate through ‘matchingRecords’ IDs, retrieve and manipulate as needed
matchingRecords.forEach(function(recordId) {
var gr = new GlideRecord('your_table_name');
if (gr.get(recordId)) {
// Perform your operations on each matching record
}
});
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 03:27 AM
Hi @MichaelZischeck ,
In that case you can use gr.addOrCondition() this will work for you, you can refer below code for reference
var qc = gr.addQuery('short_description', 'Test);
qc.addOrCondition('sys_tags.b', <sys_id here>);
qc.addOrCondition('sys_tags.b', <sys_id here>);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 04:22 AM
unfortunately it won't... add OR Condition will always ^OR, I need ^NQ.
It's 2 totally unrelated queries and I need the results of both