- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 06:02 AM
Hi All,
I have created a custom table (u_release_schedule) and this contains the fields u_start_date and u_product
I now need to create a schedule job to Automatically run a script of your choosing - I am going to get this to run daily and need to add a condition to check the u_release_schedule tables, u_start_date field and u_product fields/
I want the scheduled job to only run when the product = 'Strata' & current date = u_start_date
Just wondering if anyone had some pointers in regards to comparing the date in the field to the current date?
Any help is greatly appreciated
Thanks
Sam
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 02:22 AM
I've just had a look, that will be because gs.nowDateTime() does not have a date property. I was thinking of new GlideDateTime(); the below should work.
var date = new GlideDateTime().date;
var sched = new GlideRecord('u_release_schedule');
sched.addQuery('u_product', 'strata');
sched.addQuery('u_start_date', date);
sched.query();
if (sched.next()) {
var gr = new GlideRecord('rm_release');
gr.initialize();
gr.cmdb_ci = sched.u_configuration_item;
gr.u_release_product = sched.u_product;
gr.u_cdl_scheduled_start_date = sched.getDisplayValue('u_start_date');
gr.u_cdl_scheduled_end_date = sched.getDisplayValue('u_end_date');
gr.insert();
}
In your logs above you will have only got [object GlideRecord] as a result for sched in the first log, this is because it's still looking at the query, when logging you should log the properties directly or else it will always come back with that.
If you search for 'Scripts - Background' in the nav pane at the left you are able to run scripts and log anything you need using gs.print directly to the page, however, background scripts do run the full script so if you use that module make sure that you're not making full changes to the system that may cause system issues.
There is also a handy addon called Xplore which allows you to look at the properties and subfunctions for further debugging.
Kind Regards
Links:
Background Scripts — ServiceNow Elite
Be a Rockstar Developer with Xplore: Developer Toolkit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 02:37 AM
It's not so much a different way of logging, using gs.log() should suffice in most situation.
When using Scripts - Background you can add gs.print(), as soon as the script has finished running it will populate the page with the results from the print, I probably just worded it wrong. Try the below in Scripts - Background and you will see what I mean.
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
while (inc.next()) {
gs.print(inc.short_description);
}
This will just print all of the short descriptions of active incidents to the screen. I use this method when not getting responses from queries or to fiddle with queries to make sure there is a response before adding into a script.
Kind Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 02:48 AM
Thanks Chris, really helpful