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)

use WEB API(v8.2) in using JS

(0) ShareShare
ReportReport
Posted on by 1,562
Hello All,
I have a requirement where need to use WEB API(v8.2) in using JS.
once we will change "Potential Customer" field in opportunity form we have to look
into associated account form and there need to look into associated "custom_entity" entity and get the
"custom_field" field value(Boolean), which we have to set back in opportunity form's "custom_field" field. Can anyone suggest me please.
 
I have tried below code, but not getting custom look field value :
 

function retrieveEntity(entityname, id, columnset) {
var serverURL = Xrm.Page.context.getClientUrl();
var Query = entityname + "(" + id + ")" + columnset;
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v8.2/" + Query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200)//to verify result is OK {
var data = JSON.parse(this.response);
if (data != null && data.a != null)
alert(data.accountnumber);
if (data != null && data._primarycontactid_value != null)
alert(data.primarycontactid_value); //for lookup id

} else {
var error = JSON.parse(this.response).error;
alert(error.alert);
}
};
req.send();
}


function getInfo() {
debugger;
var Id = null; //primary Account key (GUID)
try { Id = Xrm.Page.getAttribute('customerid').getValue()[0].id.replace('{', '').replace('}', '');} catch (ex) { Id = null; }
if (Id !== null) {
var entityName = "accounts";
var columnSet = "?$select=customfield"; //list of column that we want to fetch
retrieveEntity(entityName, Id, columnSet);

}
}

output -  not getting customelookup_Id value:

[org_url]/api/data/v8.2/$metadata#accounts(name,customelookup_Id,emailaddress1)/$entity",
"@odata.etag":"W/\"5570886\"",
"name":"Test user","emailaddress1":null,
"accountid":"15026883-1642-e311-899e-005056ab004d"

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello Tin,

    If your custom field is a lookup then you have to select it using the 'lookup pattern' which is:

    _fieldname_value

    If your custom field's name is 'new_customfieldid' (don't forget the prefix), then the select would be

    $select=_new_customfieldid_value

    Reference docs:
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/query-data-web-api#retrieve-data-about-lookup-properties (see section 'Retrieve data about lookup properties')

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