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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Trying to retrieve custom entity using javascript but getting [Object Object] on alertbox

(0) ShareShare
ReportReport
Posted on by 840

 I am trying to return Price of an custom entity RegistrationFee. But alert box shows  [Object Object]

What am I doing wrong here? Any help will be greatly appreciated. Thanks. 

Code:

function GetDetails() {
LookupFieldObject = Xrm.Page.data.entity.attributes.get('fund_registrationfees');
if (LookupFieldObject.getValue() != null) {
var EntityId = LookupFieldObject.getValue()[0].id;
EntityId = EntityId.replace('{', '').replace('}', '');
if (EntityId != null) {
oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
RetrieveRecord(EntityId, oDataPath);
}
}
}
function RetrieveRecord(Id, ODataPath) {
try {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", ODataPath + "/fund_registrationfeeSet(guid'" + Id + "')", true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveReqCallBack(this);
}
retrieveReq.send();
}
catch (err) {
var text = "There was an error on this page.\n\n";
text += "Error description: " + err.message + "\n\n";
text += "Click OK to continue.\n\n";
alert(text);
}
}
function retrieveReqCallBack(retrieveEntityReq) {
var PrefixText = ""
if (retrieveEntityReq.readyState == 4) {
retrieveEntityReq.onreadystatechange = null;
alert(retrieveEntityReq.status);
if (retrieveEntityReq.status == 200) {
var retrievedEntity = JSON.parse(retrieveEntityReq.responseText).d;

alert(retrievedEntity.hasOwnProperty("fund_Price"));
alert(retrievedEntity.fund_Price);


}
}
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    crmUserMN Profile Picture
    840 on at
    RE: Trying to retrieve custom entity using javascript but getting [Object Object] on alertbox

    That worked ! My final code:

    var Price = retrievedEntity.fund_Price.Value;

    Xrm.Page.getAttribute("fund_price").setValue(parseFloat(eval(Price)));

    Thanks a lot for your help. I really appreciate this !

  • Verified answer
    Royal King Profile Picture
    27,686 on at
    RE: Trying to retrieve custom entity using javascript but getting [Object Object] on alertbox

    try with alert(retrievedEntity.fund_Price.Value);

  • crmUserMN Profile Picture
    840 on at
    RE: Trying to retrieve custom entity using javascript but getting [Object Object] on alertbox

    Chitra,

    Thanks for your reply. But fund_Price is a currency field. Do I need to use any specific retriever function here? Thanks.

  • Royal King Profile Picture
    27,686 on at
    RE: Trying to retrieve custom entity using javascript but getting [Object Object] on alertbox

    What is the data type of fund_Price ? Is it lookup ? if so try alert with below code to get Id of the lookup

    alert(retrievedEntity.fund_Price.Id);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans