Worknotes should be updated to catalog task when it is updated on RITM

shivani39
Tera Expert

Hi All,

 

Can we copy worknotes in the task when it is updated in RITM of a catalog.

I have tried the below Business rule, looks like after and async is not working and when trying with Before, I am getting an error "Before Business Rules should not modify records on other tables".

 

I have kept the filter to run this BR on one specific catalog only with update/insert option.

 

(function executeRule(current, previous /*null when new*/ ) {
//if (current.cat_item.sys_id == '9690844b1b0e7f406380777b1d4bcb28') {
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', current.sys_id);
tasks.query();
while (tasks.next()) {
gs.info('update worknotes');
tasks.work_notes = current.work_notes;
tasks.update();
}
// }
})(current, previous);

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@shivani39 Use the following BR script to copy work notes from RITM to SC Task.

 

(function executeRule(current, previous /*null when new*/ ) {
    //if (current.cat_item.sys_id == '9690844b1b0e7f406380777b1d4bcb28') {
    var tasks = new GlideRecord('sc_task');
    tasks.addQuery('request_item', current.sys_id);
    tasks.query();
    while (tasks.next()) {        
        tasks.work_notes = current.work_notes.getJournalEntry(1);
        tasks.update();
    }
    // }
})(current, previous);

Always use work_notes.getJournalEntry(1); to get the latest work notes.

 

Hope this helps.

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@shivani39 Use the following BR script to copy work notes from RITM to SC Task.

 

(function executeRule(current, previous /*null when new*/ ) {
    //if (current.cat_item.sys_id == '9690844b1b0e7f406380777b1d4bcb28') {
    var tasks = new GlideRecord('sc_task');
    tasks.addQuery('request_item', current.sys_id);
    tasks.query();
    while (tasks.next()) {        
        tasks.work_notes = current.work_notes.getJournalEntry(1);
        tasks.update();
    }
    // }
})(current, previous);

Always use work_notes.getJournalEntry(1); to get the latest work notes.

 

Hope this helps.

@Sandeep Rajput 

 

This has failed the testing, looks like the same worknote is appearing with task number multiple times. Meaning, if we have 3 task created for one RITM, the same worknotes from RITM is appearing along with 3 task number on the worknotes of the task. Please refer below image. We just want one worknote to appear. Could you please help.

 

shivani39_0-1682514404177.png

 

@shivani39 Looks like you haven't put a condition on the business rule on RITM. Please update the business rule condition as follows.

 

Screenshot 2023-04-26 at 9.05.06 PM.png

Here in item choose the catalog item for your RITM where you would like to copy the worknotes

Also, make sure to keep work notes change condition.

 

Hope this helps.

@Sandeep Rajput 

Hello Sandeep, these conditions I have already kept. The thing is "Before" BR isn't working and throwing Best practice error(before BR cannot be used in other table). So I have used "After" BR, which is copying the actual worknotes in the task, but also copying the worknotes of 2nd task. Please refer image.

shivani39_1-1682677167483.png

 

 

shivani39_0-1682677073079.png