how to open alert/dialog box on clicking on close button of Transaction

workflow or script to add a confirm popup when someone attempts to close a Purchase Order?


Many time accidently we clicked on close button on transaction record which results in closing of that record. what if we have any functionality where after clicking on button confirm box come and we can choose of we really need that or not.
there are 2 ways to do this.
1. make custom button and do close the record

we can do this using workflow or user event . If we are using workflow then we have to use workflow also also as to close record we have to close all lines "isclosed" is the column field .
if we are using user event then we can do everything in in same script , but only user event will not help, we need client script also.
as we can not add client script in view mode so we have to use user event to add button and then add client script on user event before load. No need to deploy client script. in user event only
add form.setScript("clientscriptid");
//-------------- this is user event deployed to PO.
function addclient(type, form,request)
{
    form.setScript('customscript748');//customscript748  this is id of client script created above

    form.addButton('custpage_buttoncs','Close','clientscriptfunction();');   
}


2. find native function which triggered on Close Button click. In my case it was "close_remaining" I am hoping this will be same ,

then add one user event before load and one client script. in client script override native function with you function and add confirm box .



//------------- this is client script , you can make it undeployed if you want
var org_foo = window.close_remaining;
//Assigning proxy fucnc
window.close_remaining = function(args){
    //Performing checks
    var r = confirm("Want to close ");
    if (r == true) {
        org_foo(args);
    } else {
       
    }

       
   
};

//-------------- this is user event deployed to PO.
function addclient(type, form,request)
{
    form.setScript('customscript748');//customscript748  this is id of client script created above
}

Comments