How to send mail to approver on ritm if any comment has been made in the ritm by the requestor

Shalika
Tera Expert

How to send mail to approver on ritm if any comment has been made in the ritm by the requestor

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello Shalika,

I am not sure what will be the best approach to implement this requirement in your instance but you can do the following:

1. Create an event in sysevent_register table with Name as sc_req_item.commented.approver and Table as sc_req_item.

2. Create an after update BR on sc_req_item table with condition and script as shown below:

Script Condition: current.comments.changes() && gs.getUserID() == current.requested_for

(function executeRule(current, previous /*null when async*/ ) {
    var lastComments = current.comments.getJournalEntry(1);
    var approverList = [];
    var sysApprovalGR = new GlideRecord("sysapproval_approver");
    sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue() + "^state=requested");
    sysApprovalGR.query();
    while (sysApprovalGR.next()) {
        approverList.push(sysApprovalGR.getValue("approver"));
    }
    if (approverList.length && lastComments) {
        gs.eventQueue("sc_req_item.commented.approver", current, approverList, lastComments);
    }

})(current, previous);

3. Create a notification on sc_req_item table with below details:

find_real_file.png

find_real_file.png

Subject: ${number} has been commented by ${requested_for}

in Message field you can put the below content:

find_real_file.png

You can make changes as per your requirement in email content.

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

View solution in original post

7 REPLIES 7

Uncle Rob
Kilo Patron

Flow Designer with these steps roughly

Flow Properties:  Run on every update

TRIGGER:  On update of sc_req_item where comments changes

1.  Look up records:  Approvers where approval task = trigger's sc_req_item

2.  For each of (1)

3.  Send Notification

Mahendra RC
Mega Sage

Hello Shalika,

I am not sure what will be the best approach to implement this requirement in your instance but you can do the following:

1. Create an event in sysevent_register table with Name as sc_req_item.commented.approver and Table as sc_req_item.

2. Create an after update BR on sc_req_item table with condition and script as shown below:

Script Condition: current.comments.changes() && gs.getUserID() == current.requested_for

(function executeRule(current, previous /*null when async*/ ) {
    var lastComments = current.comments.getJournalEntry(1);
    var approverList = [];
    var sysApprovalGR = new GlideRecord("sysapproval_approver");
    sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue() + "^state=requested");
    sysApprovalGR.query();
    while (sysApprovalGR.next()) {
        approverList.push(sysApprovalGR.getValue("approver"));
    }
    if (approverList.length && lastComments) {
        gs.eventQueue("sc_req_item.commented.approver", current, approverList, lastComments);
    }

})(current, previous);

3. Create a notification on sc_req_item table with below details:

find_real_file.png

find_real_file.png

Subject: ${number} has been commented by ${requested_for}

in Message field you can put the below content:

find_real_file.png

You can make changes as per your requirement in email content.

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

Snow Angel
Tera Expert

I must say this was an excellent solution provided by @Mahendra RC