Auto update field values

devservicenow k
Tera Contributor

My requirement is to Auto update field values after 5 days of creation.

Record is created--> after 5 days --> short_description (" alert 5 days) field should be auto updated.

how to do this in Schdeuled job?

8 REPLIES 8

Mark Manders
Mega Patron

Why not use a wait condition in a flow? But in a scheduled job you could run it daily, check on the created day and add it to the short description.

But: why? What is your use case? Your end users will also see that addition, since the short description is visible for end users. What issue are you trying to resolve by this functionality?

If my answer helped you in any way, please then mark it as helpful.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Martin Ivanov
Giga Sage
Giga Sage

In the scheduled job put this script. Replace your table with your table .

var nowMinusFiveDays = new GlideDateTime();
nowMinusFiveDays.addDaysUTC(-5);

var grTable = new GlideRecord('your_table');
grTable.addQuery('sys_created_on','<', nowMinusFiveDays);
grTable.query();

grTable.setValue('short_description', 'your warining string');
grTable.updateMultiple()

 

Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Yeah its working , after that 5 days the shortdescription is getting updated.

i need the script that after another 5 days , the state should automatically get closed. how to do that, after your given script.

var nowMinusFiveDays = new GlideDateTime();
nowMinusFiveDays.addDaysUTC(-5);

var grTable = new GlideRecord('your_table');
grTable.addQuery('sys_created_on','<', nowMinusFiveDays);
grTable.query();

grTable.setValue('short_description', 'your warining string');
grTable.updateMultiple()

Hi @devservicenow k ,

You can update script as below to change short description after 5 days and close after 10 days

var nowMinusFiveDays = new GlideDateTime();
nowMinusFiveDays.addDaysUTC(-5);

var grTable = new GlideRecord('your_table');
grTable.addQuery('sys_created_on','<', nowMinusFiveDays);
grTable.query();

grTable.setValue('short_description', 'your warining string');
grTable.updateMultiple();

var nowMinusTenDays = new GlideDateTime();
nowMinusTenDays.addDaysUTC(-10);

var grTable = new GlideRecord('your_table');
grTable.addQuery('sys_created_on','<', nowMinusTenDays);
grTable.query();

grTable.setValue('state', 'value of closed'); //update backend value of state and closed
grTable.updateMultiple();

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth