Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

When the state changes to resolved need current date and time on sc task in the custom field name(reopen date/time).

Shweta Kasbe1
Tera Contributor

I need current date/time on sc task r(esolved field) when state ritm state changes to resolved 

I tried using br but didn't work.Please help me in this.

var gr2 = new GlideRecord('sc_task');
var gdt = new GlideDateTime();
current.u_resolved_time = gdt;
gdt.addDays(2);
gr2.update();

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your BR would be after update on RITM

State [Changes to] Resolved

Script:

var gdt = new GlideDateTime();
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery("request_item", current.getUniqueValue());
taskRec.query();
while(taskRec.next()){
	taskRec.setValue("u_resolved_time", gdt);
	taskRec.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

Write after BR on the RITM table

Use below script:

var gdt = new GlideDateTime();
var resolvedDate = gdt.addDays(2);
var gr2 = new GlideRecord('sc_task');
gr2.addQuery("request_item", current.getUniqueValue());
gr2.query();
While(
   
   gr2.setValue("u_resolved_time", resolvedDate);
   gr2.update();
}

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions šŸ™‚

 

 

Best Regards
Aman Kumar

I tried for script but its not working. Also i have put this conditionfind_real_file.png

The BR should be after update and not insert, because you want to run the BR whenever there is a update on RITM form.

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions šŸ™‚

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your BR would be after update on RITM

State [Changes to] Resolved

Script:

var gdt = new GlideDateTime();
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery("request_item", current.getUniqueValue());
taskRec.query();
while(taskRec.next()){
	taskRec.setValue("u_resolved_time", gdt);
	taskRec.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader