The CreatorCon Call for Content is officially open! Get started here.

Worknotes is not getting updated

Drishti
Tera Guru

Hello Community ,

 

There is one Date field on HR case form. The date value entered in the date field, when matches to todays date then state should change to WIP and work-notes should get updated with comments.

 

The challenge is here - I have created one scheduled script so that when date matches to todays date then state should change along with that work-notes should get updated. But this work-notes is not getting updated every time. Like sometimes , it work and sometimes it won't.

 

I also tried different way of script like setting work-notes without setWorkflow(false) then calling a function where I am setting state value along with setWorkflow(false).
But this too is not working.

 

My script : 

 

var grCase = new GlideRecord('sn_hr_core_case');
grCase.addEncodedQuery(MYQUERY);
grCase.query();
while (grCase.next()) {
grCase.work_notes = " MY COMMENTS FOR WORKNOTES";
grCase.update();
setStateValue(grCase);
 
}

function setStateValue(hrCase) {

hrCase.setValue('state', '18');
hrCase.autoSysFields(false);
hrCase.setWorkflow(false);
hrCase.update();

}
 
I have multiple BR and notification on condition of "State changes to WIP" . So, if I won't use setWorkflow(false) then that too will create an issue.
 
Please guide how can I achieve this.

Thanks !
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Drishti 

you can use scheduled flow which runs daily and see if the date is Today

Then use Lookup Records and use For Each and then update the record

I shared solution for something similar in past, see and enhance

I cannot seem to get an Email Notification when a record's due date is reached 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 
Thanks for your response.
But I have one doubt here , via flow also if I will set the state to WIP , it will trigger all those BR(s) and notifications(s) satisfying the condition ( state changes to WIP).

Please correct me if I am wrong.