Add sys_user_id to comments (sys_journal_field)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2012 07:58 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2012 03:20 PM
You could add the reference field and then set its default value to
. It'll capture the user account that made created the journal entry.
javascript:getUserID();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2012 03:31 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2012 02:17 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2012 07:59 AM
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.