Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the current date records from the table?

msm4
Mega Guru

Hi Team,

I have a table with date column and I am trying to get the current date records from the table using glide record.

i have used the below code snippet which i have used, but i failed to get the result.

<g:evaluate var="jvar_gr" object="true">

  var gr = new GlideRecord("cmdb_ci_outage");

  var current_date=new GlideDateTime();

  gr.addQuery('begin',current_date);

  gr.addQuery('type','outage');

  gr.query();

  gr;

</g:evaluate>

Can anyone give me solution..

Thanks in Advance.

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Smitha,



With things like this around dates, I find it easier to add an encoded query. You can go to a list of records, filter the options down to the records you're looking for, then use the query in your encoded query. For example, if I wanted all incidents created on today, I could do:



var inc = new GlideRecord('incident');


inc.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)');


inc.query();



2111f05285.png


Hey Brad,


Thanks for the response   , let me try this...


Thanks Brad , its working ....


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Glad it's working, please mark my reply correct or helpful so it's easier for others to find.