Cancel reason should capture in resolution notes

Arun61
Tera Contributor

I have a requirement. We have cancel Ui action on incident form when user clicks on cancel button then addition comment will be mandatory user enter cancellation reason. 

Now we need to capture Cancellation reason in resolution note.

canceled by: - (if caller canceled then caller name or cancled by integration then system)
reason for cancellation: - (Additional comments)

 

Can anyone help on this.

1 ACCEPTED SOLUTION

@Arun61 

script is wrong.

alert won't work in business rule; also you are not comparing the value correctly

try this

(function executeRule(current, previous /*null when async*/ ) {
	var inccomments = current.comments.getJournalEntry(1);
	if (current.sys_updated_by == current.caller_id.user_name) {
		current.close_notes = "Customer cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
	} else if ((current.caller_id.ebond == true &&  current.sys_updated_by == current.caller_id.user_name)) {
		current.close_notes = "system cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
		gs.log("ebond" + current.u_customer);
	} else if (current.sys_updated_by == current.assigned_to.user_name) {
		current.close_notes = "Manual Cancellation" + "\n" + "Cancellation Reason : " + inccomments;
	}
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Arun61 

so what script did you start with and where are you stuck?

share the script and UI action screenshot

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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 based on updatedby user comments should capture)
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 ;
        gs.log("ebond" + current.u_customer);
    } else if (current.sys_updated_by == "assigned_to") {
        current.close_notes = "Manual Cancellation" + "\n" + "Cancellation Reason : " + inccomments;
    }
})(current, previous);

@Arun61 

script is wrong.

alert won't work in business rule; also you are not comparing the value correctly

try this

(function executeRule(current, previous /*null when async*/ ) {
	var inccomments = current.comments.getJournalEntry(1);
	if (current.sys_updated_by == current.caller_id.user_name) {
		current.close_notes = "Customer cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
	} else if ((current.caller_id.ebond == true &&  current.sys_updated_by == current.caller_id.user_name)) {
		current.close_notes = "system cancellation" + "\n" + "Cancellation Reason : " + inccomments ;
		gs.log("ebond" + current.u_customer);
	} else if (current.sys_updated_by == current.assigned_to.user_name) {
		current.close_notes = "Manual Cancellation" + "\n" + "Cancellation Reason : " + inccomments;
	}
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

If I read this correct then you need 'we need to capture Cancellation reason in resolution note.'

 

If so then you need to write a BR On the table in question

Condition - State <changes to><cancelled state>

and copy the Cancellation reason (Additional comment) to Resolution Note

canceled by: - You can again check if it is a user, and if not then add system 

canceled by: This is same as Cancellation reason but if you need to do it again you can.

-Anurag