Duplication of work notes while Copying task work notes from one task to another task of Same RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 01:57 AM
Hi All,
I have a requirement to copy Work Notes from One task to another Task of Same RITM.
I have created the Business rules After to achieve this but the issue is when i am trying to post work notes in any one of the task it is getting duplicated which is an issue for me. However it is getting copied correctly in another task of same RITM.
Please suggest how to get rid of this duplicate work notes.
Thanks,
Saaquib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 07:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 08:02 AM
@SaaquibQ You can check whether that work notes is already updated or not and then update to remove duplicate, code you might use something like below if helps you:
(function executeRule(current, previous /*null when async*/) {
// Check if current task has a work note update
if (current.work_notes.changes()) {
// Query for other tasks with the same RITM
var otherTask = new GlideRecord('sc_task');
otherTask.addQuery('parent', current.parent);
otherTask.addQuery('sys_id', '!=', current.sys_id); // Exclude current task
otherTask.query();
while (otherTask.next()) {
// Check if the work note already exists in the target task
var existingNote = new GlideRecord('sys_journal_field');
existingNote.addQuery('element_id', otherTask.sys_id);
existingNote.addQuery('name', 'work_notes');
existingNote.addQuery('value', current.work_notes);
existingNote.query();
if (!existingNote.hasNext()) {
// Copy work note to the other task
otherTask.work_notes = current.work_notes;
otherTask.update();
}
}
}
})(current, previous);
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 11:51 PM
@Abhay Kumar1 , It doesn't helps.