Wednesday, March 16, 2011

Override Add Existing ISV Button functionality in CRM

To override "Add Existing" button default functionality. An Iframe displays accounts assoiciation view. Here I will be adding an confirm alert message to the "Add Existing" button, if the user confirms it will opens the lookup window, otherwise no action will happen.






     Add the following java script code in page load of the entity



getAlertForAddExistingAccountButton = function(lookupUrl) {  
    var iframe = crmForm.all.IFRAME_Accounts; //  IFRAME_Accounts  ID  
    var crmGrid = iframe.contentWindow.document.all['crmGrid'];  
      


  // If it's not N:N lookup dialog, we skip it.   
    if (lookupUrl.toLowerCase().match(/\/_controls\/lookup\/lookupmulti.aspx/i) == null)  
        return lookupUrl;  
      
    // If the lookup window is not concerned with the entity that we are interested in, we skip as well  
    if (GetQueryString(lookupUrl, 'objecttypes') !== crmGrid.GetParameter('otc'))  
        return lookupUrl;  
  
    
    return lookupUrl;  
};

(function replaceCrmLookups() {  


    window.oldOpenStdDlg = window.oldOpenStdDlg || window.openStdDlg;  


    window.openStdDlg = function() {  
    
var cnf = confirm("Are you sure to open Account lookup? ");
if(!cnf)
return;



        arguments[0] = getAlertForAddExistingAccountButton(arguments[0]);  
        
        return oldOpenStdDlg.apply(this, arguments);  


    };  
})();


Now you will get confirm alert on add existing button click before opening the account lookup page.


No comments:

Post a Comment