web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Xrm.WebAPI.retrieveRecord not working from a button click

(0) ShareShare
ReportReport
Posted on by

Hi,

I am calling the below code from a ribbon button 'CloseAsWon' in opportunity form, it is throwing 'unable to get property 'retrieveRecord' of undefined or null reference'. Can you pls let know what am i missing. Also is that WebApi.retrieveRecord will work from ribbon context.

function CloseOpportunityCheck()
{
var owner = Xrm.Page.getAttribute('ownerid').getValue()[0].id;
owner = owner.replace(/[{}]/g, "");
//To get the businessunit of the Opportunity Owner.
Xrm.WebApi.retrieveRecord("systemuser", "+owner+", "?$select=_businessunitid_value").then(
function success(data)
{
alert('Hi');
},
function (error)
{
Xrm.Utility.alertDialog(error.message);
});
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Shidin Haridas Profile Picture
    3,499 on at

    Hi ArunG,

    According to https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/retrieverecord,  the second parameter is the record ID.

    Try the following code:

    function CloseOpportunityCheck() {
    var owner = Xrm.Page.getAttribute("ownerid").getValue()[0].id;
    owner = owner.replace(/[{}]/g, "");
    //To get the businessunit of the Opportunity Owner.
    Xrm.WebApi.retrieveRecord("systemuser", owner, "?$select=_businessunitid_value").then(
    function success(data) {
    alert('Hi');
    },
    function (error) {
    Xrm.Utility.alertDialog(error.message);
    });
    }

    If my answer helps you, please mark it as verified.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans