Business rule to copy RITM comments to all SCTASKS associated to the RITM

Bret Smith
Giga Guru

How to I update the business rule to copy RITM comments to all the TASKs created under the RITM?

 

 

Current business rule: Copy Comments from RITM to Task

This only copies the RITM Comment to the first Task .

 

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

    var com = "RITM Comments copied from " + current.number + " : " + "\n" + current.comments.getJournalEntry(1);
    if(com.indexOf('RITM Comments')>-1 && com.indexOf('Catalog Task Comments')==-1)
{
    var cattaskis = new GlideRecord('sc_task');
    cattaskis.addQuery('request_item', current.sys_id);
    cattaskis.query();
        if (cattaskis.next()) {
           cattaskis.comments= "RITM Comments copied from " + current.number + " : " + "\n" + current.comments.getJournalEntry(1);
           cattaskis.update();
        }
    }
})(current, previous);
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

In this case all you would need to do is change the 'if' to 'while' to retrieve more than one sc_task record:

while (cattaskis.next()) {

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

In this case all you would need to do is change the 'if' to 'while' to retrieve more than one sc_task record:

while (cattaskis.next()) {

Bret Smith
Giga Guru

If believe the problem is with

line 9: if (cattaskis.next()) {

should be
line 9: while (cattaskis.next()) {

 

when 'If' is used, the business rule will only add the RITM comment to the first task associated with the RITM

when 'While' is used, the business rule will add the RITM comment to ALL the tasks associated with the RITM