- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 11:18 AM
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();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 04:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 04:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 04:48 AM
Chanikya,
You may use a similar Business Rule but this time, in its script, you will query 'problem_task' table instead of 'incident', and the field: 'problem' instead of 'problem_id'.
Run a test like described and verify the result. Thank you!
Best Regards,
Georgi Mavrodiev
IT Consultant
Do IT Wise Bulgaria
You may visit us in our Web Site: www.doitwise.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 04:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 05:32 AM
here i used to Copy
ProblemTask record of worknotes into Problem record
PTASK0010004---------} into PRB0040022
PTASK0010005---------}into PRB0040022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 07:49 AM
Hello again, Chanikya,
I got your latest request wrongly the first time I red it.
So if you want to move Work notes from Problem Tasks (Child) to Problem (Parent) you will have to create a separate Business Rule:
- table - Problem Task (problem_task);
- When to run: before Update;
- Advanced > Script:
(function executeRule(current, previous /*null when async*/) {
// add a description of the BR;
var prob = new GlideRecord('problem');
prob.addQuery('sys_id', current.problem.sys_id);
prob.addQuery('sys_id','!=',current.sys_id);
prob.query();
while(prob.next()){
prob.work_notes = 'Problem Task: ' + current.number + ' work notes ' + ' : ' + current.work_notes.getJournalEntry(1);
prob.update();
}
})(current, previous);
Please have in mind that this is only for a case in which you are using the first Business Rule I wrote you to update work notes of Incident from Problem. The current BR (the second one) will be used to update work notes of Problem from Problem Task.
If you want to ensure that Problem work notes will update child Incidents and also child Problem Tasks while work notes of child Problem Task will update Problem work notes -> then you need to put some additional conditions into both the BRs in order to prevent duplication:
- both BRs will have to have the following line in their Advanced > Condition: current.work_notes.indexOf('###')<0
- also work notes texts in both BR scripts will have to contain ###, for example: 'Problem Task: ' + current.number + ' work notes ' + ' : ' + current.work_notes.getJournalEntry(1); will be changed to: '### Problem Task: ' + current.number + ' work notes ' + ' : ' + current.work_notes.getJournalEntry(1);
Chanikya, test the above BR and let me know the outcome.
While testing it, please check if no duplication of work notes appear in the Incident child records and other Problem Task child records. Thanks!
Best Regards,
Georgi Mavrodiev
IT Consultant
Do IT Wise Bulgaria
You may visit us in our Web Site: www.doitwise.com