- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 08:42 AM
Use Case: I have a scheduled job that updates duration fields every 12 hours.
- I don't want the scheduled job to create work notes, (because everyone would get notified too often, and it would clutter the notes tab).
- I do have the duration fields checked in the Activity formatter because I do want a work note created when someone manually changes the value from the form.
- I need to business rules to run when the job runs (so setWorkFlow probably won't work for this situation)
So basically: How can I prevent a scheduled job from creating work notes, but also create work notes when the field(s) are manually updated?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 11:18 AM
That was very helpful, @Arun_S1 , but it didn't quite work for me.
My solution:
- I removed the duration fields from the Activity Formatter on the form, which prevented the scheduled job to create work notes when it executed.
- Then I used your suggestion of creating a business rule to create a work note when a user manually made the change:
(function executeRule(current, previous /*null when async*/ ) {
var user = gs.getUserDisplayName().toString();
current.work_notes = user + " updated the Blocked Duration from " + previous.u_blocked_duration.getDisplayValue() + " to " + current.u_blocked_duration.getDisplayValue();
})(current, previous);​
Worked like a charm. Thanks again for the assistance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 08:50 AM
@Digit You meant the changes captured in the History? (The scheduled job is modifying the duration field, which is captured in worklog as the field content was modified from A to B)
Please mark the appropriate response as correct answer and helpful.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 09:03 AM
That's correct. I want to prevent the scheduled job from making a work note when it changes the duration field from A to B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 09:31 AM - edited ‎07-19-2023 09:34 AM
@Digit not sure if there is easy approach for this requirement. Alternatively you can
1. Disable audits for the field by adding the attribute "no_audit=true" in the dictionary for the field, this will stop capturing the changes made to the field.
2. Add a new Business Rule after insert/update with the condition "Duration Changes"
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(gs.isInteractive()){
var audit=new GlideRecord('sys_audit');
audit.initialize();
audit.tablename='incident';
audit.fieldname='description';
audit.oldvalue='Manual Entry';
//This was added to differentiate between a manual entry & ServiceNow entry, kindly change this to audit.oldvalue= previous.description;
audit.newvalue=current.description;
audit.documentkey=current.sys_id;
audit.user=gs.getUserName();
audit.record_checkpoint=current.sys_mod_count;
audit.insert();
}
})(current, previous);
The above code is for description field, please change it for Duration.
Please mark the appropriate response as correct answer and helpful.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 09:45 AM
@Arun_S1
That certainly looks like it will work, thanks! I'll try it tonight.