How do you script a historical comment into the work notes?

bradwestvig
Giga Guru

We have a custom table that was created by our implementation partner to store comments.  I want to move those comments into the work_notes and comments field on the incident table. 

I wrote a test script to test this, but it doesn't seem to show up.

var gr = new GlideRecord('sys_journal_field');
gr.element = 'work_notes';
gr.element_id = <sys_id>;
gr.name = 'incident';
gr.sys_created_by = <user_id>;
gr.value = 'some notes';

gr.insert();
1 ACCEPTED SOLUTION

After reviewing with ServiceNow, it is a system control to not allow for back dating or doing historical notes on behalf of someone.  We decided to go ahead and run the script as system, and then insert the date the original comment was added with the username.

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you forgot to intialize

var gr = new GlideRecord('sys_journal_field');
gr.initialize();
gr.element = 'work_notes';
gr.element_id = <sys_id>;
gr.name = 'incident';
gr.sys_created_by = <user_id>;
gr.value = 'some notes';
gr.insert();

Regards
Ankur

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

Thanks @Ankur Bawiskar  Good Catch on the missing initialize().  I added it, but it still doesn't show in the activity history.  You can see that I've been able to create rows in the sys_journal_field table.

find_real_file.png

Hi,

this link talks about using setWorkflow(false) during insertion but I tried that and it didn't work

Journal entries (comments or work notes) which are saved in sys_journal_field not showing in the Act...

also check this

Disabling auditing for Journal fields will break the Activity Formatter

regards
Ankur

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

I looked into both of the links you shared, and no luck.  I have verified that if I add it directly to the incident record that works.  I wouldn't be able to set the user and timestamp, if I use that approach.  I opened up a case, and will update on their response.