- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2019 01:52 AM
Hi all,
I have to update some records in Change table i.e i have to set work start with created date , work end with created +30 seconds .
I have written like below but not working
Can you please help
var gr= new GlideRecord('change_request');
gr.addEncodedQuery('short_descriptionLIKEISPW-change^active=true^sys_created_by=ispw');
gr.setLimit(2);
gr.query();
while(gr.next())
{
gr.work_start = gr.sys_created_on;
gr.requested_by_date = gr.sys_created_on;
var date = new GlideDateTime('sys_created_on');
gr.work_end = date.addSeconds(10);
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2019 02:55 AM
Try
var gr= new GlideRecord('change_request');
gr.addEncodedQuery('short_descriptionLIKEISPW-change^active=true^sys_created_by=ispw');
gr.setLimit(2);
gr.query();
while(gr.next())
{
gr.work_start = gr.sys_created_on;
gr.requested_by_date = gr.sys_created_on;
var date = new GlideDateTime(gr.sys_created_on);
date.addSeconds(30);
gr.setValue('work_end', date.getValue());
//gs.print(date.getValue());
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2019 06:03 AM
no its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2019 06:35 AM
Quick question: are you needing all three values to be the 'updated' sys_created_on value? Or is it that the work_start and requested_by_date are both to be 10secs behind the new date value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2019 07:05 AM
I went back and checked on your original post where you said "i have to set work start with created date , work end with created +30 seconds". So here is a slightly modified version of my script excerpt which should do just that:
{
var gdt = new GlideDateTime(current.sys_created_on);
current.work_start = gdt.getValue();
var date = new GlideDateTime(gdt);
date.addSeconds(30);
current.work_end = date.getValue();
}
However, a lot also comes down to your actual query being correct otherwise the script will never run.
