
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2019 07:59 AM
Hi all,
I'm trying to set up a scheduled job that runs off a variable on the sc_item_option table called 'Termination Date'.
The problem I have is that the value in the sc_item_option table has converted the value to a string, therefore when i try to put a query on date, it isn't recognizing the value as a date.
Is it possible to store this value as a date so we can query on it..?
Thanks guys
Rich
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 01:56 AM
Hi,
How about querrying sc_req_item itself, sample code would be below
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
// Use can add more filter condition here to filter the number of records
gr.query();
while (gr.next()) {
var vars = gr.variables;
for ( var v in gr.varibles ) {
if ( v == "giveTheNameOfTheVariableHere") {
var dateTime = new GlideDateTime(gr.variables[v].toString());
// Write your logic here based on your calculations, now you have DateTime Object access via variable dateTime
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 01:57 AM
Ah oke. The scheduled job, is that just made out of conditions etc.. Or also scripting?
The scripting part does not have to be that hard. Just quickly tested below code with background script as example. This created a Date type out of a String.
var dateStr = '2019-06-19';
var glideDate = new GlideDateTime(dateStr);
gs.info(glideDate);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2019 09:38 AM
Hello Richard,
While your idea of adding a custom field to store the value as a date is intriguing, I'm curious about why you don't just query the table using a string set to the value which corresponds to the query's date?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 01:39 AM
Hi Hugo,
Thanks for your reply - We need to run a scheduled job each night to pick up expired termination dates. My level of coding is low so I'm just searching for answers - could we do that with what you've described above...?
Thanks for your time.
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 01:56 AM
Hi,
How about querrying sc_req_item itself, sample code would be below
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
// Use can add more filter condition here to filter the number of records
gr.query();
while (gr.next()) {
var vars = gr.variables;
for ( var v in gr.varibles ) {
if ( v == "giveTheNameOfTheVariableHere") {
var dateTime = new GlideDateTime(gr.variables[v].toString());
// Write your logic here based on your calculations, now you have DateTime Object access via variable dateTime
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2019 03:35 AM
Hi Deepak,
Thanks for this! we tweaked it slightly but it works a charm 🙂
Many thanks.
Richard