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

setJournalEntry not working correctly, in many ways

yvan
Tera Contributor

setJournalEntry is behaving inconsistently for us when running a script that mass closes and appends a journal entry to a chosen list of tasks; at times it will work correctly, at others we are seeing three incorrect behaviors for setJournalEntry:

  1. No entry appears at all in Activities, but does appear in sys_journal_field
  2. The string value provided for the Username is ignored and username of user that ran the script is entered instead.
  3. Entry is shoehorned somewhere in the middle of the Activity, with a user and timestamp associated with Update 0 in the History List, instead of the correct information in the sys_audit table

We are setting setUseEngines to false to prevent some of our automated behaviors from occurring instead of setWorkflow, as setJournalEntry doesn't even work when we use setWorkflow. 

 

EDIT/UPDATE

After some additional investigation the sys_audit table shows the correct information for all of the edited tasks.
However the Activity stream and History List are showing completely erroneous information.

Original script was run in a subprod and all tested tasks looked perfect there. Only after running this in production instance did things go completely sideways.

8 REPLIES 8

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Instead of using setJournalEntry, you can just do this:

RECORDNAME.comments = "your comments" and this will create a journal entry.  Please note that setValue() does not work with journal fields as mentioned here:

https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_refe...

I'll remember that for the future, but the damage has been done so far.

I suppose we'll need to undo what the script has done and try a script RECORDNAME.comments = "your comments" instead.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Sorry to hear damage has been done.  I would highly recommend running mass scripts like this in a test environment first.

I know this doesn't help you now, but there is a Rollback feature coming in London!

https://community.servicenow.com/community?id=community_blog&sys_id=27804903db63530054250b55ca961938

 

Please mark any post as helpful or the correct answer to your question so others may benefit.

Oh yes, we did, and it was all perfect there, I seem to have neglected to mention that though. I'll edit appropriately.