copy the ritm comments to task

Rajveer
Tera Expert

Hello Expert,

 

When ever the 1st task will generated whatever all comment on ritm would be copy over to task in servicenow with timestamp.

 

How can archive this

1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@Rajveer 

I think you can write before business rule on task table, below is the sample code you can use :

 

(function executeRule(current, previous /*null when async*/) {
    // Check if this is the first task created for the RITM
    if (current.number.startsWith('TASK') && current.number.split('.')[1] === '1') {
        // Retrieve comments from the RITM
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(current.parent)) {
            var ritmComments = ritm.comments.getJournalEntry(-1);
            // Copy comments to the task
            if (ritmComments) {
                current.comments = "Comments from RITM:\n" + ritmComments;
                current.update();
            }
        }
    }
})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rajveer 

 

Might be helpful

 

https://www.servicenow.com/community/developer-forum/copy-comments-from-ritm-to-task-vice-versa/m-p/...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Community Alums
Not applicable

Hi @Rajveer ,

Please check below code 

var taskGr = new GlideRecord('sc_task');
    taskGr.addQuery('request_item', current.sys_id);
    taskGr.query();
        if (taskGr.next()) {
           taskGr.comments = current.comments;
           taskGr.update();
        }
    }

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Maddysunil
Kilo Sage

@Rajveer 

I think you can write before business rule on task table, below is the sample code you can use :

 

(function executeRule(current, previous /*null when async*/) {
    // Check if this is the first task created for the RITM
    if (current.number.startsWith('TASK') && current.number.split('.')[1] === '1') {
        // Retrieve comments from the RITM
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(current.parent)) {
            var ritmComments = ritm.comments.getJournalEntry(-1);
            // Copy comments to the task
            if (ritmComments) {
                current.comments = "Comments from RITM:\n" + ritmComments;
                current.update();
            }
        }
    }
})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks