Background script to update date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2021 02:58 AM
Hello!
I need to update the retirement date of assets with a specific date using background script. This is my script but it does not work.
var gr = new GlideRecord('clm_m2m_contract_asset');
gr.addEncodedQuery('<insert query>');
gr.query();
while (gr.next()) {
gr.retirement_date = '2022-01-30';
gr.setWorkflow(false);
gr.update();
}
Please help!
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2021 03:06 AM
Try in this way
var gr = new GlideRecord('change_request');
gr.addQuery('number','CHG123456');
gr.query();
if(gr.next())
{
gr.start_date = new GlideDateTime("2020-08-27 13:30:00");
gr.end_date = new GlideDateTime("2020-08-28 00:30:00");
gr.u_outage_start_date = new GlideDateTime("2020-08-27 13:30:00");
gr.u_outage_end_date = GlideDateTime("2020-08-28 00:30:00");
gr.u_closed_by_date = GlideDateTime("2020-09-04 14:30:00");
gr.setWorkflow(false);
gr.update();
gs.print(gr.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2021 03:18 AM
Hi,
So what date it set?
Are you using correct query and got correct count of records?
Is the field name correct?
var gr = new GlideRecord('clm_m2m_contract_asset');
gr.addEncodedQuery('<insert query>');
gr.query();
gs.info('Row Count' + gr.getRowCount());
while (gr.next()) {
gr.retirement_date = '2022-01-30';
gr.setWorkflow(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
‎06-07-2021 07:04 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
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
‎07-01-2021 04:41 AM
Hope you are doing good.
Did my reply answer your question?
Would you mind marking the best matching answer as correct and helpful, to close this thread?
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader