Show alert on click of "approve" action in employee center approvals

mr18
Tera Guru
Tera Guru

How can I show alert on click of "approve" action in employee center approvals under My task

13 REPLIES 13

Community Alums
Not applicable

Hi @mr18 ,

 

Go to this widget, inside Client controller, add the alert like this:

Screenshot 2023-12-03 at 01.04.13.pngScreenshot 2023-12-03 at 01.06.26.png

Thank you @Community Alums for the reply.

I want to show the alert only if the approval is coming from specific catalog item.

So is there any possibility where I can check the condition something like source_table is sc_req_item and cat_item is xyz.

 

Really appreciate for your help

 

Thank you

 

Community Alums
Not applicable

@mr18 , I just successfully implemented this but will involves with interacting with multiple Employee Center widgets including cloning and modifying both Client and Server scripts.

Let's see if we have any other alternative methods from anyone else

Amit Gujarathi
Giga Sage
Giga Sage

HI @mr18 ,
I trust you are doing great.
You can add the confirmation box

Client script :

function confirmApproval() {
    var currentRecord = g_form.getUniqueValue(); // Gets the unique ID of the current record

    // AJAX to get details from the server
    var ga = new GlideAjax('CustomApprovalCheck'); // 'CustomApprovalCheck' is the Script Include you'll create
    ga.addParam('sysparm_name', 'checkApprovalSource');
    ga.addParam('sysparm_record_id', currentRecord);
    ga.getXML(checkResponse);

    function checkResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer === 'true') {
            var conf = confirm("Are you sure you want to approve this task?");
            return conf; // Proceed with or cancel the action based on user choice
        } else {
            return true; // Proceeds normally if the condition is not met
        }
    }
}

 

Script include :

var CustomApprovalCheck = Class.create();
CustomApprovalCheck.prototype = {
    initialize: function() {
    },

    checkApprovalSource: function(recordId) {
        var gr = new GlideRecord('approval'); // Assuming 'approval' is the table
        gr.get(recordId);
        if (gr.source_table == 'sc_req_item' && gr.cat_item == 'xyz') { // Replace 'xyz' with the sys_id of the specific catalog item
            return 'true';
        }
        return 'false';
    },

    type: 'CustomApprovalCheck'
};

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi