PowerShellservicenowsnow

Tips: Working with Date and Time in servicenow REST API using PowerShell

Retrieve all incidents created on this month programmatically. Indeed, it’s very simple and straight forward approach when it comes to reportings right? No, we aren’t focusing reporting table (sys_report) for now. Instead I go with simple query!

Using PowerShell it’s very easy to find start and end of the month! Yes, try the below PowerShell snippets and let me know your thought!

Beginning of the month

End of the Month

Cool! But in service now we don’t need to use this for retrieving incidents created on ‘THIS MONTH’. Yes, servicenow makes job easier using inbuilt javascript functions which is used in the sysparm_query like illustrated  below.

sysparm_query=sys_created_onONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()

Here is the full code!

Output

This works for weekly reports and all readily available options. If in case you need to make custom dates you can very well adopt the below option

sysparm_query=sys_created_on>’2018-08-08%3223:59::59

In my next blog I will show custom queries using PowerShell until then enjoy PowerShell!

Leave a Reply

Your email address will not be published. Required fields are marked *