incident Additional comments should capture in clode notes

Arun61
Tera Contributor
Hi i was trying with the below business rule but the comments are not capturing from the addition comments to close_notes.
(Actual requirment is when incident is canceled additional comments field is mandatory those comments should capture based on updatedby user)
if caller canceled then :- customer cancellation
if integration user cancels :- system cancellation
can you please check the below script and correct it
when to run:- before insert and update
state changes to cancelled
 
(function executeRule(current, previous /*null when async*/ ) {
    var inccomments = current.comments.toString();
    if (sys_updated_by == "callerid") {
        alert("test callerid");
        current.close_notes = "Customer cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
    } else if ((current.callerid.ebond == true &&  current.sys_updated_by == "callerid")) {
        current.close_notes = "system cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
  
    } else if (current.sys_updated_by == "assigned_to") {
        current.close_notes = "Manual Cancellation" + "\n" + "Cancellation Reason : " + inccomments;
    }
})(current, previous);
2 REPLIES 2

KevinBellardine
Kilo Sage

Hey @Arun61 

 

The first thing I noticed is in many places you're trying to access 'caller id' and 'sys_updated_by' as variables instead of properties of current. For example, in your first if statement. Even after you correct this you'll have to dotwalk onto the user record if you want to compare sys_updated_by. Make sure that everything you're referencing is either a variable you've already defined or a property of something like current.

 

You should also use getValue unless you're dotwalking, and if you're dotwalking you should use toString or +''

 

Other than that the logic here seems sound. I'd wonder if people are ever going to be populating close notes themselves since your code would effectively overwrite anything someone manually put into the form.

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @Arun61 ,

 

Comment is a journal entry field. So you cannot access it as a string. You have to use '.getJournalEntry' method with parameter 1 to get the latest comment (.getJournalEntry(1)). And in sys_updated_by take the user_name of the user.

Refer to the below code for your requirement:-

 

(function executeRule(current, previous /*null when async*/ ) {
        var com = current.comments.getJournalEntry(1); // get the latest comment
        var inccomments = com.slice(com.indexOf(')') + 1).trim();//get the string part
        if (sys_updated_by == current.caller_id.user_name) {
            current.close_notes = "Customer cancellation" + "\n" + "Cancellation Reason : " + inccomments;
        } else if ((current.callerid.ebond == true && current.sys_updated_by == current.caller_id.user_name)) {
            current.close_notes = "system cancellation" + "\n" + "Cancellation Reason : " + inccomments;

        } else if (current.sys_updated_by == current.assigned_to.user_name) {
            current.close_notes = "Manual Cancellation" + "\n" + "Cancellation Reason : " + inccomments;
        }
    })(current, previous);

 

 

If this response clears up your doubt, kindly flag it as both helpful and correct.

Thanks,

Alka