Business Rule to update Comments with Close Notes

cnharris1
Kilo Sage

Good morning everyone,

I'm trying to write a business rule that updates the Comments (Customer Visible) field with the information provided in the Close Notes field once the technician decides to resolve the ticket. I know this information can be seen in the Activity, however, I need the Comments field to be updated with the Close Notes field for my organization. I have provided a copy of my script, which should be simple but I'm having some trouble. The script is on the Incident table and runs on an update after Close Notes is not empty (I think that's correct):

(function executeRule(current, previous /*null when async*/) {
 current.comments = current.close_notes.getDisplayValue(); 
})(current, previous);

 

Any help will be greatly appreciated!

Best regards,

cnharris

1 ACCEPTED SOLUTION

cnharris1
Kilo Sage

Thanks Prateek! I tried using the code and it does work but it just doesn't work on the comments field for some reason. I think it has something to do with that field being an array but I'm not too certain. I did find a workaround to my problem and I provided the link below:

https://community.servicenow.com/community?id=community_question&sys_id=9997c7a9db1cdbc01dcaf3231f961933&view_source=searchResult

 

View solution in original post

8 REPLIES 8

Prateek kumar
Mega Sage

Try changing the condition to Close Notes Changes and Script to the following

(function executeRule(current, previous /*null when async*/) {
 current.comments = current.close_notes; 
})(current, previous);

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

cnharris1
Kilo Sage

Thanks Prateek! I tried using the code and it does work but it just doesn't work on the comments field for some reason. I think it has something to do with that field being an array but I'm not too certain. I did find a workaround to my problem and I provided the link below:

https://community.servicenow.com/community?id=community_question&sys_id=9997c7a9db1cdbc01dcaf3231f961933&view_source=searchResult

 

Glad that you were able to resolve. 

Please mark the appropriate response as correct/helpful and close this thread.

 

-Cheers

Prateek


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Yong Zeng Lee
Tera Contributor

For anyone that may need this in future:

in your business rule, set the condition for your use case, e.g. Incident State changes to Resolved

in your script, use the setJournalEntry method to update the comments field:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.comments.setJournalEntry(current.close_notes, current.assigned_to);
	
})(current, previous);

 

 

Regards,

Yong Zeng