Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Not able to enable/disable button through workbench as I cannot make Xrm.WebApi synchronous

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Not able to enable/disable button through workbench as I cannot make Xrm.WebApi synchronous

    Yes I checked, that didn't help.

    I am going through only one entity and based on the value i get i need to return a Boolean value.

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Not able to enable/disable button through workbench as I cannot make Xrm.WebApi synchronous

    Hi Sinduja,

    Did you checked in below url ?

    blog.thenetw.org/.../

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans