- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2025 08:28 AM
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 :
Thanks !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2025 11:41 PM
Hi @Drishti,
The issue is: setWorkflow(false) prevents all business rules — including system logic that updates journal fields like work_notes. That’s why your comments sometimes disappear.
Here’s the clean, reliable solution 👇
✅ Final Working Script
var grCase = new GlideRecord('sn_hr_core_case');
grCase.addEncodedQuery(MYQUERY);
grCase.query();
while (grCase.next()) {
// Store Sys ID before manipulating workflows
var sysId = grCase.getUniqueValue();
// Step 1: Update work notes safely (with workflow ON)
grCase.work_notes = "MY COMMENTS FOR WORKNOTES";
grCase.update(); // Let this trigger normally (ensures notes get written)
// Step 2: Update state quietly (no notifications, no BRs)
var grSilent = new GlideRecord('sn_hr_core_case');
if (grSilent.get(sysId)) {
grSilent.setWorkflow(false);
grSilent.autoSysFields(false);
grSilent.setValue('state', '18'); // WIP
grSilent.update();
}
}🔍 Why this works
The first update writes work notes correctly because setWorkflow(false) is not used.
The second update (separate GlideRecord instance) changes state silently — no BRs, no notifications, no duplicate triggers.
Using a fresh record (grSilent) ensures no workflow caching or update conflicts.
⚠️ Notes
Don’t try to set both fields in one update if setWorkflow(false) is true — that’s why you saw inconsistency.
Keep the “silent” update isolated to avoid blocking journal updates.
Make sure your scheduled job runs with a user who has rights to update HR Cases and journal fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2025 11:13 PM
the script I shared should update work notes and state both.
Any BR is stopping the update to work_notes field?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2025 11:18 PM
I do have tried the same script in my first attempt then tried the script posted by me.
There are several communities link saying that work-notes are journal entries which gets updated by BR only. So, if we will write setWorkflow(false) then this will not work as expected .
On the same time, we have to update state value as well which will fire other BR and notification satisfying the conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2025 02:30 AM
yes got it.
It's an OOTB behavior.
then try this other workaround and insert record into sys_journal_field table
var grCase = new GlideRecord('sn_hr_core_case');
grCase.addEncodedQuery(MYQUERY);
grCase.query();
while (grCase.next()) {
grCase.setValue('state', '18'); // WIP
grCase.setWorkflow(false); // Avoid triggering BRs if that's intended
grCase.autoSysFields(false); // Prevent auto-update on sys fields
grCase.update();
// insert data into table
var rec = new GlideRecord('sys_journal_field');
rec.initialize();
rec.name = grCase.getTableName();
rec.value = 'MY COMMENTS FOR WORKNOTES';
rec.element = 'work_notes';
rec.element_id = grCase.sys_id;
rec.insert();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2025 09:31 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2025 11:41 PM
@Ankur Bawiskar
sys_journal_field is having lots of records and may hamper system performance.