GlideSystem Date Functions On Dev Instance

chriscorbett
Giga Contributor

All --

I'm wondering if there is a limitation on the GlideSystem date function on dev instances? I am incorporating query strings into a few jelly scripts on a dev instance. Queries I pulled for today work, as does a query for yesterday.

But if I put in a query that specified a start and end date, that does not work no matter what I try.

So, for example, this query to pull records for today is working:

var dateString = "entry_dateONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)";

  var target = new GlideRecord('tablename');

  target.addEncodedQuery(dateString);

  target.query();

But this attempt where I try to pull records from this past Sunday until today is NOT working:

  var dateString = "entry_dateBETWEENjavascript:gs.dateGenerate('2016-03-06','start')@javascript:gs.dateGenerate('2016-03-08','end')";

  var target = new GlideRecord('x_27491_hi_tracker_daily_stats');

  target.addEncodedQuery(dateString);

  target.query();

It seems that any time I try to specify a specific date in some way the query does not work.

Is there a reason for this and if so how do I correct it?   Basically, I'm trying to retrieve results from the Sunday of that given week to the current time.

If anyone can show me a better way of doing this or explain what I might be doing wrong in my query, I would appreciate it!

Thanks,

Chris

8 REPLIES 8

chriscorbett
Giga Contributor

Thanks Goran. I changed my code per your suggestion to go against the incident table and I still get nothing....



Here's my code:



  var dateString = "opened_atBETWEENjavascript:gs.dateGenerate('2016-02-07','00:00:00')@javascript:gs.dateGenerate('2016-02-10','23:59:59')";


  var target = new GlideRecord('incident');


  target.addEncodedQuery(dateString);


  target.query();


chriscorbett
Giga Contributor

So I took a look at the system logs and I see this:



com.glide.script.fencing.MethodNotAllowedException: Function dateGenerate is not allowed in scope x_27491_hi_tracker
  Caused by error in null.4 at line -1



This would seen to confirm what Goran said. But why would a function of the system not be allows in the scope of my application?


I didn't pay so much attention on this since we haven't started to make our own applications like this. But what if you replace gs.dateGenerate with global.gs.dateGenerate. Like before, just something back in my head... I'll try to remember to look in my course paper tomorrow at work.



//Göran


No go. The error in the log is now Invalid object in scoped script