sc_item_option variable

Richard Thomas2
Tera Contributor

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'. 

find_real_file.png

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.

find_real_file.png

Is it possible to store this value as a date so we can query on it..?

Thanks guys

 

Rich

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

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
            }
      }
}

View solution in original post

10 REPLIES 10

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

HugoFirst
Kilo Sage

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?

Richard Thomas2
Tera Contributor

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

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
            }
      }
}

Richard Thomas2
Tera Contributor

Hi Deepak,

Thanks for this! we tweaked it slightly but it works a charm 🙂

 

Many thanks.

Richard