Encoded query filter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 01:08 PM
Can someone show me how to filter records in contract table (ast_contract)
I want to build a encoded query to run scheduled job for contracts that will expire on 180 days and 365 days
I have the below script for 90th day
var cnt = new GlideRecord("ast_contract");
cnt.addEncodedQuery('endsRELATIVEGT@dayofweek@ahead@89^endsRELATIVELT@dayofweek@ahead@91');
cnt.query();
while (cnt.next()) {
gs.eventQueue('reminder_contract_90_days', cnt, cnt.number);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 05:41 PM
Hi, testing quickly in a PDI your code works for me and generates a sysevent, if I set suitable end date on a contract.
Can you clarify your issue\question as it it not very clear.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 05:53 PM
Hello,
You can navigate to list view for that table and filter as you need. Once the filter is built accordingly, you can right-click the last piece of the breadcrumb and choose copy query, then paste that between double-quotes for your line, for example:
cnt.addEncodedQuery("paste_here");
endsRELATIVEGT@dayofweek@ahead@179^endsRELATIVELT@dayofweek@ahead@181^NQendsRELATIVEGT@dayofweek@ahead@364^endsRELATIVELT@dayofweek@ahead@366
The above is an example. Please take this information and go from here.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 08:44 AM
Thanks Allen! Can you show me the filter condition you kept to build that query?
Already in the system I have individual event generated based on single scheduled job that runs daily and email action sent for every 30/60/90 days of expiry
Now the requirement is to extend the scope to 180 and 365.
My question is
1. Can I create one job which checks all 30/60/90/180/365 days of expiry as one single job. I dont know why there is separate job for each event. IF i combine will that work?
Is there any script if you could help have a single job?
2. If its not necessary I would create seperaate jobs for each. I am trying to understand why there is multiple jobs to generate events. Please help me understand.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2022 05:10 AM
Hello,
You can use one scheduled job to search for records whose expiry matches your conditions of 30/60/90/180/365, etc.
As far as the filter that I built, it's just using the "relative" operator and then use 1 day on either side of the specific value. Example:
- End date "relative" after 29 days from now
- End date "relative" before 31 days from now
Then insert an "OR" and then build the next set:
- End date "relative" after 59 days from now
- End date "relative" before 61 days from now
Once you've built all filter conditions, you can right-click the last piece of the bread crumb trail, copy query, then paste as your addEncodedQuery between double quotes as I've stated above.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!