How to Copy Problem record Work Notes into Related Incident work notes

chanikya
Tera Guru

Hi,

Not working my BR script

After

Condition: current.work_notes.changes()

var updateInitiatedBy = updateInitiatedBy || current.sys_id.toString();
(function executeRule(current, previous /*null when async*/) {

// Add your code here

if(updateInitiatedBy == current.sys_id.toString()){
var gr = new GlideRecord('incident');
gr.addQuery('problem_id',current.sys_id);
gr.query();
while(gr.next()){
gr.work_notes = current.work_notes;
gr.update();
}
}

 

 

1 ACCEPTED SOLUTION

Or you can use the same Business Rule as for Incident Work notes -> simply specify a second variable:

 

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

// This Business Rule ensures that if there is a Parent Problem record, which has one or more Incidents records associated to it as Child Incidents or Problem Task(s) -> then, whenever the Work notes of the Problem get updated -> the Work notes of all Child Incidents & Problem Tasks will be updated accordingly with the same text;


// var rec = Child Incident(s);
var rec = new GlideRecord("incident");
rec.addQuery("problem_id", current.sys_id);
rec.addActiveQuery();
rec.query();
while (rec.next()) {

rec.work_notes = "Incident Work note copied from Parent Problem" + ':' + current.work_notes.getJournalEntry(1); // //Choose a text of your own, which suits you;
rec.update();
}


// var prtask = Child Problem Task(s);
var prtask = new GlideRecord("problem_task");
prtask.addQuery("problem", current.sys_id);
prtask.addActiveQuery();
prtask.query();
while (prtask.next()) {

prtask.work_notes = "Problem Task Work note copied from Parent Problem" + ':' + ' ' + current.work_notes.getJournalEntry(1);
prtask.update(); //Choose a text of your own, which suits you;
}

})(current, previous);



Best Regards,
Georgi Mavrodiev

IT Consultant
Do IT Wise Bulgaria

You may visit us in our Web Site: www.doitwise.com

View solution in original post

29 REPLIES 29

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

// Add your code here

var count=0;

if(updateInitiatedBy == current.sys_id.toString()){
var gr = new GlideRecord('incident');
gr.addQuery('problem_id',current.sys_id);
gr.query();
while(gr.next()){

count++;
//gr.work_notes = current.work_notes.getJournalEntry(1);
//gr.update();

}

gs.log('count of incident'+count);
}

})(current, previous);

 

can you run now and check the log , see how many numbers are coming and match 

have you checked the log?

 

Hello Chanikya,



You may try the following - create a Business Rule with the following characteristics:
- Name: (add such);
- Table: Problem (problem);
- Application: Global;
- Advanced: checked;
- When to run: before | update;
- Advanced > Script:

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

// This Business Rule ensures that if there is a Parent Problem record, which has one or more Incidents records associated to it as Child Incidents -> then, whenever the Work notes of the Problem get updated -> the Work notes of all Incidents will be updated accordingly with the same text;

var rec = new GlideRecord("incident");
rec.addQuery("problem_id", current.sys_id);
rec.addActiveQuery();
rec.query();
while (rec.next()) {

rec.work_notes = "Incident Work note copied from Parent Problem" + ':' + current.work_notes; // Here you may change the text in "" to whatever you want or simply remove it;

rec.update();
}

})(current, previous);


I hope this approach will be of use to you.
Please try it and let me know the outcome. Thank you!


Best Regards,
Georgi Mavrodiev

IT Consultant
Do IT Wise Bulgaria

You may visit us in our Web Site: www.doitwise.com

Thanks,

find_real_file.png

 

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

var rec = new GlideRecord("incident");
rec.addQuery("problem_id", current.sys_id);
rec.addActiveQuery();
rec.query();
while (rec.next()) {

rec.work_notes = "Incident Work note copied from Parent Problem" + ':' + current.work_notes.getJournalEntry(1); // Here you may change the text in "" to whatever you want or simply remove it;

rec.update();
}

Hello Chanikya,



Nice! Thank you for coming back to me!


Please add couple of Incident records to the Problem one, as his children and perform additional tests to confirm all records are properly updated.
Then, remove one Incident to confirm the logic stops working once 'Problem' (problem_id) field of Incident's 'Related Records' section gets cleared, as we would expect it.


Best Regards,
Georgi Mavrodiev

IT Consultant
Do IT Wise Bulgaria

You may visit us in our Web Site: www.doitwise.com