Schedule Report to include the requested Items numbers as links

Shree Nag
Tera Expert

Hello All !

 

I have a report that has a list of the requested items pending approval by the users.

I have scheduled this report which sends an email to each user reminding them to go to a dashboard to approve their requests.

 

Would it possible to include the requested Item numbers that they are approving as link to each individual user.

Here is the script that is on the scheduled report condition.

Appreciate your response.

 

 

answer = lookupUsersAndUpdateReport();

 

function lookupUsersAndUpdateReport(){

 

// look up "assigned_to" people -- assumes "table" is task-based

 

var senderArray = [];

 


var taskQueryGR = new GlideRecord(current.report.table);

 

taskQueryGR.addEncodedQuery(current.report.filter);

 

taskQueryGR.query();

 

while (taskQueryGR.next()){

 

senderArray.push(taskQueryGR.assigned_to + '');

 

}

 


current.user_list = senderArray.join(',');

 

current.setWorkflow(false);

 

current.update();

 

current.setWorkflow(true);

 


// only return true if there were records listed in the result set

 

if (senderArray.length > 0){

 

return true;

 

}

 

return false;

 

}

2 REPLIES 2

Shree Nag
Tera Expert

FYI for follow up, attached is the image showing filter conditions for the report.

Mark Manders
Mega Patron

I think you will run into issues when doing that. Not every approver has rights to view the RITM's. That you can approve and see data from a RITM doesn't mean you can also see the RITM itself. Then you will send an email with links that end up in 'you don't have sufficient privileges...'. That will cause a lot of questions.


And sending the approvals as link, would also not be my advise. You actually just want to send them to the portal, to the overview of their approval records, so they can do their job. 

In case you do want all of the RITMs to be send as links, you will need to do that in the email script. Find all of the records and the related record to approve and add them to the email. You can use this as starting point: 

(function() {
    var userId = gs.getUserID(); // Get the current user's Sys ID
    var baseUrl = gs.getProperty('glide.servlet.uri'); // Get the base URL of the instance
    var approvals = new GlideRecord('sysapproval_approver');
    var links = "";

    approvals.addQuery('approver', userId);
    approvals.addQuery('state', 'requested'); // Assuming 'requested' is the state for open approvals
    approvals.query();

    while (approvals.next()) {
        var recordSysId = approvals.sys_id.toString();
        var recordTable = approvals.document_id.getTableName();
        var recordLink = baseUrl + recordTable + '.do?sys_id=' + recordSysId;

        links += "<a href='" + recordLink + "'>Approve " + approvals.document_id.getDisplayValue() + "</a><br>";
    }

    // This variable `links` can be used in the email template
    template.print(links); // Prints the links to be included in the email body
})();

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark