- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:22 AM
HI service now team,
I am trying to Update date /time fields value on a closed incident through background script , but iam unable to update them through the background script i have written . but iam unable to acheive any results , can you correct my script if there is anything wrong or suggest me good scripting for updating the fields.
iam trying to update this fields
Restore date (empty field value to )==>Mar-18-2022 10:10:00 PM,
Actual End date (existing old value)==> Mar-18-2022 11:05:00 PM
var work_end = "03-18-2022 10:10:00";
var u_user_services_restored_date_ = ' ';
var gr= new GlideRecord('incident');
gr.addEncodedQuery('u_major_incident=true^incident_state=7^number=INC3486819');
//gr.setLimit(2);
gr.query();
while(gr.next())
{
gr.work_end = gr.getDisplayValue();
gr.setValue("work_end",'03-18-2022 11:05:00');
gr.setValue("u_user_services_restored_date_",'03-18-2022 10:10:00');
gr.setWorkflow(false);
gr.autoSysfields(false);
gr.Update();
}
Can any one of you could help me in this and provide me a good solution. thanks .
Regards,
Ghouse sharief
Solved! Go to Solution.
- Labels:
-
Major Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:45 AM
Hi,
try this for 2 records and verify and then comment setLimit() line of code
var work_end = "2022-03-18 23:05:00";
var u_user_services_restored_date_ = ' ';
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_major_incident=true^incident_state=7');
gr.setLimit(2);
gr.query();
while(gr.next())
{
gr.work_end = new GlideDateTime(work_end);
gr.setValue("work_end", new GlideDateTime(work_end));
gr.setValue("u_user_services_restored_date_", new GlideDateTime('2022-03-18 22:10:00'));
gr.setWorkflow(false);
gr.autoSysfields(false);
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:29 AM
I think date value format is: yyyy-mm-dd hh:MM:ss
Can you try that format in you script?
And do you get an error, when running it as a background script?
Regards,
Michael
Michael
Please mark the suggestion as helpful/like, if you find it useful to you or others who wants to refer similar content.
Please mark the solution as correct, if the answer provided has resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:38 AM
Hi michael ,
I tried it but it is not working and not displaying any results . No iam not getting any error.
Thanks .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 02:45 AM
Hi,
try this for 2 records and verify and then comment setLimit() line of code
var work_end = "2022-03-18 23:05:00";
var u_user_services_restored_date_ = ' ';
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_major_incident=true^incident_state=7');
gr.setLimit(2);
gr.query();
while(gr.next())
{
gr.work_end = new GlideDateTime(work_end);
gr.setValue("work_end", new GlideDateTime(work_end));
gr.setValue("u_user_services_restored_date_", new GlideDateTime('2022-03-18 22:10:00'));
gr.setWorkflow(false);
gr.autoSysfields(false);
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 04:02 AM
Hi Ankur,
That actually worked , thanks for your help .