- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2014 04:54 PM
Hi all, several of my technicians have requested a feature that would allow them to set a signature that would appear automatically when they update Incidents. We had this functionality in our old ticketing system and our people like to have a friendly and human touch when talking with our customers.
Anyway, to set this up, I just created two new fields on the user table, one to hold a signature and one to toggle it on or off. I am now trying to use a Business Rule to insert the signature after comments. Sounds easy enough, right?
Anyway, for some reason the comment itself is repeating after the signature is inserted. For example, say my signature is '- Ben, Field Tech' and I make a comment on an Incident that says "All done - I fixed the computer. Have a great day!". What shows up in the activity feed is:
All done - I fixed the computer. Have a great day!
- Ben, Field Tech
All done - I fixed the computer. Have a great day!
The code the business rule runs is just:
current.comments += "\n\n" + userSignature
Any ideas why it's doing this or how I can fix?
Thanks!
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2015 10:39 AM
I ended up solving this by creating a Business Rule to run on Display and pass the UserSignature values to the session in the g_scratchpad object.
I could then use a client script (instead of a Business Rule) to insert the Signature on Insert of the Incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2015 10:39 AM
I ended up solving this by creating a Business Rule to run on Display and pass the UserSignature values to the session in the g_scratchpad object.
I could then use a client script (instead of a Business Rule) to insert the Signature on Insert of the Incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2016 07:23 AM
Hey Ben,
We are dealing with exactly the same situation and used the solution you suggested. We made an onSubmit() client script that appends the signature just before submitting the form. This works fine if the user updates/saves the record. However, when the user makes use of the 'Post' button next to the comments field, the script is not triggered. Did you also encounter this issue and, if so, how did you tackle this?
Kind regards,
Joris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 02:29 AM
As per Geoffrey's suggestion, we went for the hard option . We've managed to implement a script that updates the last added comment and adds the user's signature. Note that this function could be adapted to modify any journal field entry, but we implemented it only for the edit-last-entry case. Our solution:
/**
* Edits the last inserted journal field entry. If the journal is empty, nothing is edited
*
* @param GlideRecord record The record to edit journal field of
* @param String field The journal field to edit
* @param String newvalue The new entry value
* @return String The previous value or null if no edit was made
*/
function editLast( record, field, newvalue ) {
var recordID = record.sys_id.toString( );
// first edit the current value
var journal = new GlideRecord( 'sys_journal_field' );
journal.addQuery( 'element_id', recordID );
journal.addQuery( 'element', field );
journal.orderByDesc( 'sys_created_on' );
journal.setLimit( 1 );
journal.query( );
if( !journal.next( ) ) return null;
// disable edit of sys_fields, this would generate a new comment
journal.autoSysFields( false );
var oldvalue = journal.value.toString( );
journal.value = newvalue;
journal.update( );
// modify the associated audit record
var audit = new GlideRecord( 'sys_audit' );
audit.addQuery( 'documentkey', recordID );
audit.addQuery( 'fieldname', field );
audit.orderByDesc( 'sys_created_on' );
audit.setLimit( 1 );
audit.query( );
// check if audit exists
if( !audit.next( ) ) return oldvalue;
audit['new'] = newvalue;
audit.newvalue = newvalue;
audit.autoSysFields( false );
audit.update( );
// and finally update the history
var hist = new GlideRecord( 'sys_history_line' );
hist.get( 'audit_sysid', audit.sys_id.toString( ) );
if( !hist.isValidRecord( ) ) return oldvalue;
//Refresh the history set
var hist_set = hist.set.id.getRefRecord();
if(typeof GlideHistorySet != 'undefined')
GlideHistorySet( hist_set ).refresh();
else
Packages.com.glide.audit.HistorySet( hist_set ).refresh();
// return the previous field value
return oldvalue;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2020 01:48 AM
Hi!
I know this post is a few years, but I have a similar problem. I implemented your script in a before update BR, and am still getting double posts?
Also, would the implementation affect any notifications triggered by added additional comments? (I haven't had the opportunity to test this yet).