Regarding script logic to be created on clicking a UI Action

Appu2
Tera Contributor

Hi,

My requirement is:

We need to create a NEW UI Action named Change approval button. This will cancel the existing approval and allow you to select new approvers. Also we already have a Request Approver field through which we select the Approver and then after clicking another "Request Approval" UI Action, approval gets triggered to the person selected in that field.

We need to show confirm message box for the new UI Action ,'Are you sure you want to change the Approver, this will cancel the existing approvals?'

On Yes, it should cancel the requested approval and allow you to select a new approver in Request Approver field.

 

Can anyone help me with the script for this scenario?

Any inputs here!

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Hi @Appu2 ,

(function newfunctionexcute() {
    if (g_form.isNewRecord()) {

    } else {
        if (confirm("Are you sure you want to change the Approver? This will cancel the existing approvals.")) {
            // User confirms, allow them to proceed.

            // Cancel existing approvals by updating their state to "canceled."
            var approvalGR = new GlideRecord('approvals');
            approvalGR.addQuery('parent', g_form.getUniqueValue()); // Assuming approvals are related to the current record.
            approvalGR.addQuery('state', 'requested'); // You may want to specify the state you want to cancel.
            approvalGR.query();
            while (approvalGR.next()) {
                approvalGR.state = 'canceled';
                approvalGR.update();
            }
            g_form.setValue('request_approver', ''); // Clear the existing approver
            // You can prompt the user or provide a way to select a new approver.
        }
    }
})();

 

Thanks,

Anand 

I have written the below script which should execute if the user clicks on the button and hit OK to proceed further. But the issue is it's not doing anything once I click on "Ok" on the confirm message box.

function changeApproval() {
       var usrResponse = confirm("Are you sure you want to change the Approver? This will cancel the existing approvals.");
       if (usrResponse.toString() == 'false') {
           return false; //Abort submission
       } else {
           
           var approvalGR = new GlideRecord('sysapproval_approver');
           approvalGR.addQuery('sysapproval', gs.getUniqueValue());
           approvalGR.addQuery('state', 'requested');
           approvalGR.query();
           if (approvalGR.next()) {
               approvalGR.state = 'cancelled';
               approvalGR.update();
           }
           gs.setValue('request_approver', ''); // Clear the existing approver
           // You can prompt the user or provide a way to select a new approver.
       }
Any inputs here?
 

Appu2
Tera Contributor

Can anybody help in resolving what's the issue with my code as it's not executing