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,558
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

  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at
    RE: use WEB API(v8.2) in using JS

    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans