Copy Work Notes from Problem to Incident and Vice Versa

Chintha Murali
Kilo Expert

Hi All,

I have a requirement to copy worknotes from problem to incident and vice versa. 

Please help me with this.

Thank you.

1 ACCEPTED SOLUTION

Hi @Chintha Murali krishna 

 

Please find the updated Business Rules below (these will surely work 😉)

Remark: Make sure both the Business Rules are on Insert and Update + When = Before

Incident:

(function executeRule(current, previous /*null when async*/ ) {
    var identifier = '[Comment Sync]';
    if (current.work_notes.indexOf(identifier) < 0) {
        var getProblems = current.problem_id.getRefRecord();
        getProblems.work_notes = identifier + '\n' + current.work_notes;
        getProblems.update();
    }
	
})(current, previous);

Problem:

(function executeRule(current, previous /*null when async*/ ) {
    var identifier = '[Comment Sync]';
    if (current.work_notes.indexOf(identifier) < 0) {
        var getIncidents = new GlideRecord('incident');
		getIncidents.addQuery('problem_id', current.getValue('sys_id'));
		getIncidents.query();
		while(getIncidents.next()) {
			getIncidents.work_notes = identifier + '\n' + current.work_notes;
			getIncidents.update();
		}
    }
	
})(current, previous);

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

View solution in original post

7 REPLIES 7

Hi,
tested your code and it works fine, IF the incident does not have any other related records. 
When incident has 'change reguest' as related record, every time comment is copied, the script creates empty change ticket and the only thing on the empty record is the worknote that was copied to incident from problem

RonankiChandu
Tera Contributor

It's working Thanks

 

Eswar Chappa
Mega Sage
Mega Sage

Hi@Kartik Sethi can you suggest any other approach instead of keeping Identifier, In my use case it  was just a sync should happen from Incident to Problem and Vice versa!

 

Thanks & Regards,

Eswar Chappa