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

Kartik Sethi
Tera Guru
Tera Guru

Hi @Chintha Murali krishna 

 

This requirement will have recursive work notes/comment updates so we need to have a workaround for this.

  1. Create a Business Rule on both Incident and Problem tables
  2. Business Rule names can be
    • Incident:
      • Copy Work notes to Problem
    • Problem:
      • Copy Work notes to Incident
  3. Both the Business Rules (BRs) should run on Insert and Update, and Can run on After
  4. Condition on BRs should be Worknotes changes
  5. Decide a common identifier to avoid recursive copy of comments on Incident and Problem
  6. Scripts are provided below:

Incident:

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

 

find_real_file.png

 

Problem:

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

 

find_real_file.png

 

 


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

Hi Karthik,

Thank you for the detailed explanation. I have tried your solution but it still doesn't work. Please have a look at the screenshots attached.

find_real_file.png

 

find_real_file.png

 

Thank you

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

Thank you. It works perfectly.