Update Work Notes of a HR Case through Fix Script

Madhan007
Tera Contributor

Hi Everyone ,

I am trying to close some old cases through a Fix script without triggering Notifications to Opened for, Subject Person and Approvers with the below script.

var hrc = new GlideRecord('sn_hr_core_case');

hrc.addQuery('number', 'HRC0044626');

hrc.query();

while (hrc.next()) {

    hrc.setWorkflow(false);

    hrc.autoSysFields(false);

    hrc.work_notes = "Closed through Fix Script";

    hrc.state = '7';

    hrc.active = false;

    hrc.update();

}

But I cant update the work notes field. 
when I use hrc.work_notes = " ", its not being updated unless something is posted in the worknotes manually.
setValue() and setJournalEntry() is not working.

Please pour your Suggestions.

Thank You!

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

This is due to the "setWorkFlow(false)" statement.

It prohibits the worknotes creation to be shown on the case, even though the record exists.

 

You can work your way around it by doing the update in two steps (see attached example).

Also, be aware that you could possibly get more than one record by query on the number.

If you want exactly one record, you should use the sysID as qualifier instead.


Also, I would recommend using the setValue method of GlideRecord whenever possible.

 

var hrc = new GlideRecord('sn_hr_core_case');
hrc.addQuery('number', 'HRC0044626');
hrc.query();

while (hrc.next()) {

    hrc.setWorkflow(false);
    hrc.autoSysFields(false);
    hrc.state = '7';
    hrc.active = false;
    hrc.update();

    hrc.setWorkflow(true);
    hrc.work_notes = "Closed through Fix Script 2 parts solution.";
    hrc.update();

}

 

 

 

View solution in original post

7 REPLIES 7

Chaitanya ILCR
Kilo Patron

Hi @Madhan007 ,

 

delete the sys_history_set records of the record

the work notes will reflect

ChaitanyaILCR_0-1750746130504.png

 

refer responses in below thread

https://www.servicenow.com/community/csm-forum/close-case-script-add-work-notes/m-p/3276191

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Hi @Madhan007 

If you check the journal entry table the work note entry would be there

It's just that it's won't show up the form with setworkflow false sometimes 

 

Delete the history set records for the records

The work notes will show up

 

 

Regards 

Chaitanya 

Aniket Chavan
Tera Sage
Tera Sage

Hello @Madhan007 , @

I actually faced the same issue before. The problem is likely due to the setWorkflow(false) and autoSysFields(false) lines in your script. Since work_notes is a journal field, these settings can prevent it from being updated properly.

Try removing both lines and run the script again — it should update the work notes as expected.

Hope that helps!

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket



OlaN
Giga Sage
Giga Sage

Hi,

This is due to the "setWorkFlow(false)" statement.

It prohibits the worknotes creation to be shown on the case, even though the record exists.

 

You can work your way around it by doing the update in two steps (see attached example).

Also, be aware that you could possibly get more than one record by query on the number.

If you want exactly one record, you should use the sysID as qualifier instead.


Also, I would recommend using the setValue method of GlideRecord whenever possible.

 

var hrc = new GlideRecord('sn_hr_core_case');
hrc.addQuery('number', 'HRC0044626');
hrc.query();

while (hrc.next()) {

    hrc.setWorkflow(false);
    hrc.autoSysFields(false);
    hrc.state = '7';
    hrc.active = false;
    hrc.update();

    hrc.setWorkflow(true);
    hrc.work_notes = "Closed through Fix Script 2 parts solution.";
    hrc.update();

}