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

Notifications

Announcements

No record found.

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)
  • Royal King Profile Picture
    27,686 on at

    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);

  • crmUserMN Profile Picture
    840 on at

    Chitra,

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

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    try with alert(retrievedEntity.fund_Price.Value);

  • Verified answer
    crmUserMN Profile Picture
    840 on at

    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 !

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans