Add sys_user_id to comments (sys_journal_field)

rajabhadury
Kilo Explorer

I'm integrating a third party app with ServiceNow and am looking at showing the incident comments, along with a picture of the users which made the comments. The default sys_journal_field has a "created by" field, but this is only a text field (of the first.lastname). The issue is that the first.lastname is not unique in the system, so you do not know which user will be returned if you do a lookup for the user based solely on this field.

I can add in the reference field (to sys_user) to the sys_journal_field, but am unsure of how/where to set this when a comment is created. Was wondering if anyone had any suggestions?

Much obliged
Raja

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You could add the reference field and then set its default value to


javascript:getUserID();
. It'll capture the user account that made created the journal entry.


CapaJC
ServiceNow Employee
ServiceNow Employee

One clarification: sys_created_on is the user_name of the user who made the comment. Again, not necessarily unique, but probably moreso than first.last

For comments, that's the identifier used since it won't be cleared if the user's sys_user record is subsequently deleted. A reference field will get cleared.


rajabhadury
Kilo Explorer

CapaJC - Yes, very true. It just happens our username fields are stored in the format first.lastname. I can definitely see the point if the user's record is deleted.

b-rad - Exactly what I'd like to do! Ideally, I'd like to modify the code that is setting the parameters for the comment in the first place (and add in the user_id as well as what is on there currently), rather than creating a business rule which finds the last comment when an incident.comments.changes() and set the user_id there. Is this possible to do?


You can actually accomplish this without modfying any code or adding a new business rule. Just add a new field that references the user table and in the dictionary entry for the new field, set the default value field to javascript:gs.getUserID();. It will automatically pick up the user who made the comment without any extra rules.