Hi Community, I need to trigger notifications on sys approval table

rajeshKongamudi
Tera Contributor

Hello Community,

We are attempting to retrieve the "Requested For" and "Opened By" fields from the sysapproval table, but we are currently unable to retrieve these values. We would appreciate assistance in triggering the "Requested For" and "Opened By" fields. Below, I have outlined the trigger conditions and the event script.

We would be grateful for any guidance on how to resolve this issue and implement the necessary enhancement. Thank you in advance for your support.

 

rajeshKongamudi_0-1740473353564.png

Advanced script: 

--------------------------------

(function executeRule(current, previous /*null when async*/) {
    // Add your code here
var values = current.sysapproval.variables;
gs.eventQueue("Freelancer_reject", current, values.requested_by, values.requested_for.email);
})(current, previous);
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@rajeshKongamudi 

use this in your script

I assume event, notification is on Approval table and Event parm1 contains Recipient checkbox is True

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here

    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
    if (gr.next()) {
        var values = gr.requested_for.toString() + ',' + gr.opened_by.toString();
        gs.eventQueue("Freelancer_reject", current, values);
    }

})(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

Sourabh Tarlekr
Kilo Sage

Hi @rajeshKongamudi 

 

Requested for and Opened By are not variables in RITM so we can directly access fields from sysapproval.

Kindly pass below parameters in your query. It should work.

 

 

gs.eventQueue("Freelancer_reject", current, current.sysapproval.requested_for.email,current.sysapproval.opened_by.email);

 

 

If this solution works for you, then kindly mark Accept Solution/Helpful.

 

Regards,

Sourabh

 

View solution in original post

5 REPLIES 5

DeependraS
Tera Expert

(function executeRule(current, previous ) {
var approvalRecord = new GlideRecord(current.sysapproval.getRefRecord().getTableName()); // Get related record
if (approvalRecord.get(current.sysapproval)) {
var requestedFor = approvalRecord.getValue("requested_for");
var openedBy = approvalRecord.getValue("opened_by");

gs.eventQueue("Freelancer_reject", current, openedBy, requestedFor);


}
})(current, previous);

 

How This Fixes the Issue

Correctly fetches the "Requested For" and "Opened By" fields from the referenced request record

Uses getRefRecord() to dynamically get the correct record type from sysapproval

Prevents errors due to missing fields in sysapproval

Toderean alexan
Tera Contributor

Hi @rajeshKongamudi 

  First of all, every time you assign a value to a variable you have to check that if is a valid value, before sending or processing. I recommend to ensure that everything is ok before sending it to event. I would like to see how you configured the notification, how you assigned the parameters? 

Ankur Bawiskar
Tera Patron
Tera Patron

@rajeshKongamudi 

use this in your script

I assume event, notification is on Approval table and Event parm1 contains Recipient checkbox is True

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here

    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
    if (gr.next()) {
        var values = gr.requested_for.toString() + ',' + gr.opened_by.toString();
        gs.eventQueue("Freelancer_reject", current, values);
    }

})(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

Great thanks for your solution, I am also facing the same issue and this solution helped me to resolve my issue. Thanks