Quantcast
Viewing all articles
Browse latest Browse all 79901

Hide subgrid '+' Add new and Add existing button by security roles using javascript

Hello experts,

I am doing hide '+ Add new' and 'Add existing' button from subgrid by security role of a user. I am getting the current user of security roles and added a condition 'if the security role is not equal to the current user security role then the subgrid button will hide. Below is my code for hiding button,

function hideAddButtonSubgrid(subgridId) {
	 try {
		 
        addEventToGridRefresh(subgridId, setAddButtonDisplayNone);
    }
    catch (e) {
 
    }
}
 
function setAddButtonDisplayNone(subgridId) {
	debugger;
     var imageId = subgridId + "_" + "addImageButton";
     if (imageId) {
        window.parent.document.getElementById(imageId).style.display = 'none';
    }
    //var imageId2 = subgridId + "_" + "addImageButtonImage";
    //document.getElementById(imageId2).style.display = 'none';
}
 
function addEventToGridRefresh(subgridId, functionToCall) {
	debugger;
	
    // retrieve the subgrid
      var grid =  window.parent.document.getElementById(subgridId);
    // // if the subgrid still not available we try again after 1 second
   
    if(grid == null){
        setTimeout(function () {addEventToGridRefresh(subgridId, functionToCall); }, 1000);
    }
 
    // add the function to the onRefresh event
     grid.control.add_onRefresh(functionToCall);
 
     var imageId = subgridId + "_" + "addImageButton";
     if (imageId) {
        if (document.getElementById(imageId).style.display.toLowerCase() == "block") {
            setAddButtonDisplayNone(subgridId);
       }
    }
    
}


When I debug this code I am getting null value at 'grid'. How can resolve this problem? Is that any issue in new UCI of dynamics 365? 


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>