I have a requirement to enable delete button in Opportunity subgrid on if the selected oppurtunity record owner is the current user. Even the function is returning correct value it is not reflected as the method is asynchronous. Please let me know how to proceed?
Below is my code
function CheckOppOwner(selectedItem)
{
var hasAccess = false;
var formContext = selectedItem;
var oppId = formContext[0].Id;
var user = Xrm.Page.context.getUserId().slice(1, -1);
Xrm.WebApi.retrieveRecord("opportunity", oppId , "?$select=_ownerid_value", false).then(function success(result) {
var ownerid = result._ownerid_value;
if(ownerid.toLowerCase() == user.toLowerCase()){
hasAccess = true; // If Opp owner is the current user
}
return hasAccess;
},
function (error) {
var message = error.message;
//Add handling of error that occurred
});
//return hasAccess;
}
*This post is locked for comments