- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 08:18 AM
Hi All,
I have a requirement to copy worknotes from problem to incident and vice versa.
Please help me with this.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 12:30 AM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:14 AM
Hi
This requirement will have recursive work notes/comment updates so we need to have a workaround for this.
- Create a Business Rule on both Incident and Problem tables
- Business Rule names can be
- Incident:
- Copy Work notes to Problem
- Problem:
- Copy Work notes to Incident
- Both the Business Rules (BRs) should run on Insert and Update, and Can run on After
- Condition on BRs should be Worknotes changes
- Decide a common identifier to avoid recursive copy of comments on Incident and Problem
- 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);
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);
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 03:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 12:30 AM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 03:56 AM
Thank you. It works perfectly.