- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2018 03:14 PM
Is there a way to determine if a current object would be captured in a query that has not been inserted? So for example, if a record is not yet inserted and you only have the current object but wanted to determine if it matched up to be captured in a query. Obviously you wouldn't be able to use a gliderecord because it hasn't been inserted. Is there another way?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 07:02 AM
If you already have an encoded query and you want to compare it to an object you can use GlideFilter.checkRecord(GlideRecord, EncodedQuery).
So for example:
If I want to validate whether the incident's caller is Joe Employee and priority is one and incident is active, the encoded query is:
var query = "active=true^priority=1^caller_id=681ccaf9c0a8016400b98a06818d57c7";
Here is a background script I use to test the encoded query against the incident:
var incident = new GlideRecord("incident");
incident.get("695505ca4f629b00d1676bd18110c7b3");
var query = "active=true^priority=1^caller_id=681ccaf9c0a8016400b98a06818d57c7";
var queryMatch = GlideFilter.checkRecord(incident, query);
gs.print("queryMatch: " + queryMatch);
The queryMatch variable will be true if it matches and false if not. Here is the result:
*** Script: queryMatch: true
Please mark any post as helpful or the correct answer to your question so others viewing can benefit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2018 04:37 PM
See the solution in this very old post:
Since you have the current object in memory, you can loop through the values to create an encoded query which is what "templateFields" is in that script and then use it to query the table to see if there is a record that matches. You may need to exclude certain fields, especially dates since they might not match up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 06:45 AM
Thanks for your reply Michael! What if I already have the query and I want to know if the current object would match that query?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 07:02 AM
If you already have an encoded query and you want to compare it to an object you can use GlideFilter.checkRecord(GlideRecord, EncodedQuery).
So for example:
If I want to validate whether the incident's caller is Joe Employee and priority is one and incident is active, the encoded query is:
var query = "active=true^priority=1^caller_id=681ccaf9c0a8016400b98a06818d57c7";
Here is a background script I use to test the encoded query against the incident:
var incident = new GlideRecord("incident");
incident.get("695505ca4f629b00d1676bd18110c7b3");
var query = "active=true^priority=1^caller_id=681ccaf9c0a8016400b98a06818d57c7";
var queryMatch = GlideFilter.checkRecord(incident, query);
gs.print("queryMatch: " + queryMatch);
The queryMatch variable will be true if it matches and false if not. Here is the result:
*** Script: queryMatch: true
Please mark any post as helpful or the correct answer to your question so others viewing can benefit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 07:44 AM
Perfect! That is exactly what I needed! I really appreciate your time.