Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Project - Notification -Create a Button which on click redirects to that sepcific approval.

Trupti Krishnam
Tera Contributor

I have a notification which runs when the project state is Screening and Approval is requested (Here the approval will also be assigned to - to whom ever the project is assigned) .and it is sent to Assigned to Now on this notification I have to create a Button called 'View Approval Task'  which on click it should redirect to that 

Specific Approval task  Something like the below image 

 

 

TruptiKrishnam_0-1758116986425.png

 

TruptiKrishnam_1-1758117327480.png

I did tried by creating a below mail script but it's not working

var message = 'View Approval Task';
    var backgroundColor = 'background-color: #152456;';
    var color = 'color: #ffffff; font-weight: bold;';
    var fontSize = 'font-size: 12px;';
    var fontBold = 'font-weight: bold;';
    var fontFamily = 'font-family: trebuchet ms, geneva;';
    var textDecoration = 'text-decoration: none; border-radius: 2px; text-align:center;';
    var display = 'display: inline-block;';
    var padding = 'padding: 10px 20px;';

    var app = new GlideRecord('sysapproval_approver');
    app.addQuery('sysapproval', current.sys_id);
    app.addQuery('state', 'requested');
    app.orderByDesc('sys_created_on');
    app.query();
        if (app.next()) {
            template.print('<a href="' + link + '"');
            template.print('style="' + backgroundColor + color + fontSize + fontBold + fontFamily + textDecoration + display + padding);
            template.print('">');
            template.print(message);
            template.print('</a>');
        }
 
but it's not working 

 

1 REPLY 1

snehareddym
Tera Guru

This is the corrected code you need to use. In the version you provided earlier, the link variable was not being populated. We need to pass a redirection link to the approval record. That’s why, in this script, I’m passing the sys_id of the approval record to generate the correct URL.

 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,

    /* Optional EmailOutbound */ email,

    /* Optional GlideRecord */ email_action,

    /* Optional GlideRecord */ event) {

 

    // Get the instance URL (used to open the approval record in the native UI)

    var instanceURL = gs.getProperty('glide.servlet.uri');

    if (instanceURL.endsWith('/')) {

        instanceURL = instanceURL.slice(0, -1);

    }

 

    // Button/Link style settings

    var message = 'View Approval Task';

    var backgroundColor = 'background-color: #152456;';

    var color = 'color: #ffffff; font-weight: bold;';

    var fontSize = 'font-size: 12px;';

    var fontBold = 'font-weight: bold;';

    var fontFamily = 'font-family: trebuchet ms, geneva;';

    var textDecoration = 'text-decoration: none; border-radius: 2px; text-align:center;';

    var display = 'display: inline-block;';

    var padding = 'padding: 10px 20px;';

 

    // Fetch the most recent pending approval record

    var app = new GlideRecord('sysapproval_approver');

    app.addQuery('sysapproval', current.sys_id);

    app.addQuery('state', 'requested');

    app.orderByDesc('sys_created_on');

    app.query();

 

    if (app.next()) {

        var link = instanceURL + '/sysapproval_approver.do?sys_id=' + app.sys_id;

        template.print('<a href="' + link + '"');

        template.print(' style="' + backgroundColor + color + fontSize + fontBold + fontFamily + textDecoration + display + padding + '">');

        template.print(message);

        template.print('</a>');

    }

 

})(current, template, email, email_action, event);

 

 

Please refer to the image below:

 

snehareddym_0-1758280531263.png

 

 

on clicking the ‘View Approval Task’ button I will be redirected to approval record in native UI , can see in below image:

snehareddym_1-1758280531275.png