Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Any way to disable creating work notes when running a scheduled job?

Digit
Kilo Guru

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?

1 ACCEPTED SOLUTION

Digit
Kilo Guru

That was very helpful, @Arun_S1 , but it didn't quite work for me. 

My solution:

  1. I removed the duration fields from the Activity Formatter on the form, which prevented the scheduled job to create work notes when it executed. 
  2. 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!!

 

View solution in original post

5 REPLIES 5

Arun_S1
Tera Guru
Tera Guru

@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!!

Digit
Kilo Guru

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

@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!!

Digit
Kilo Guru

@Arun_S1 
That certainly looks like it will work, thanks! I'll try it tonight.