- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 01:33 AM
Hi All,
I'm trying to add comments to a task form without them triggering a notification but if i use setWorkflow(false) it doesn't run the necessary rules to link the sys_journal_field record to the task form with the requisite sys_audit and sys_history_line records.
Does anyone know of a way to do this?
Cheers
Dave
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 03:09 AM
Ended up just adding an advanced condition into the incident updated for ess notification to suppress the notification when it sees a string value i'm adding into the comment when i add the email body.
Documented the whole thing as below just in case anyone else is interested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 03:28 AM
I was hoping for there to be a simple way to script it but there apparently isn't so i'm looking at adding conditions to the notification to suppress it when it see's the syntax i'm adding in to the comment when i add the email content.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 02:21 AM
Hello David,
You could write it directly to the sys_journal_field table. The reason being , data from these journal fields copied to sys_journal_field table using some Business Rule at backend. When you set workflow to false , that BR get Skipped as well.
I hope you have gone through this as well:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0684629
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 02:28 AM
I tried adding to the sys_journal_field directly but you also need to add the necessary records to the sys_audit and sys_history_line fields otherwise it doesn't show up on the activity log. I can add to the sys_audit table but can't seem to insert to the sys_history_line table.
I've checked that KB case, it's advice is to disable setWorkflow(false) which would then trigger a notification which is what i'm trying to avoid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 03:09 AM
Ended up just adding an advanced condition into the incident updated for ess notification to suppress the notification when it sees a string value i'm adding into the comment when i add the email body.
Documented the whole thing as below just in case anyone else is interested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2021 05:34 AM
For anyone that is looking for another solution. The below code example adds a Comment to an existing incident without setting the comments field. So comments.updated returns false, event incident.commented won't be created and no Notification should be sent.
In this case, we wanted to put the close notes in a comment. So the Caller can see them in the Standard Ticket widget when the incident is resolved. This is part of the before update business rule:
// Put message in Caller's language
var language = current.caller_id.preferred_language;
var message = gs.getMessageLang('Close notes:', language) + '\n' + current.close_notes;
// Create Journal Entry
// Enough when Inserted with resolved/closed/canceled state
var incSysId = current.getUniqueValue();
var incTable = current.getTableName();
var jrnlFld = new GlideRecord('sys_journal_field');
jrnlFld.initialize();
jrnlFld.setValue('element', 'comments');
jrnlFld.setValue('element_id', incSysId);
jrnlFld.setValue('name', incTable);
jrnlFld.setValue('value', message);
jrnlFld.setValue('sys_created_by', gs.getUserName());
var jrnlSysId = jrnlFld.insert();
// Create Sys Audit and History Line using GlideAuditor
// For Updated incident
if(operation === 'update'){
var prevModCount = parseInt(previous.sys_mod_count, 10);
var intCheckPoint;
if(prevModCount === 0){
// Get next 'internal_checkpoint', which is the same as internal_checkpoint for other Audit records for Update Number 1
intCheckPoint = GlideCounter.next('internal_checkpoint');
} else if(prevModCount > 0){
// Find existing 'internal_checkpoint' from [sys_history_set] to avoid slow query on [sys_audit]
var hwINC = new sn_hw.HistoryWalker(incTable, incSysId);
var grHistSet = new GlideRecord('sys_history_set');
grHistSet.get('id', incSysId); // historywalker API created History Set if needed, so we're sure it exists
intCheckPoint = grHistSet.getValue('internal_checkpoint');
}
var auditor = new GlideAuditor(incTable, incSysId); //auditor adds correct username and sets correct mod count
auditor.auditField(null, current.sys_mod_count, intCheckPoint, 'comments', 'JOURNAL FIELD ADDITION', message);
}