Notifications
Announcements
No record found.
Two questions rise up:
1.Is the type value usable to populate the entity type field if yes then how? 2.Can I populate the name attribute in the new field as is from the old field?
Example of the data that I get :
Attributes : name : "this is the name" type : "10026" __proto__ : Object Value : "{6BddfDC-8B10-47F4-BC49-A537d2E43E}"
*This post is locked for comments
Hi,
refer to below post on how to set lookup field using JS
www.magnetismsolutions.com/.../how-to-get-and-set-a-lookup-field-using-javascript-in-dynamics-365
recordid is would be = {6BddfDC-8B10-47F4-BC49-A537d2E43E}
recordName would be = "this is the name"
entityName would be = the entity name , you cannot use Object Type code (10026)
Sample Code
functin SetLookup()
{
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = "92EC3861-8D59-E811-815C-080027878DE4";
lookupValue[0].name = "Custom Team";
lookupValue[0].entityType = "team";
Xrm.Page.getAttribute("fieldname").setValue(lookupValue);
}
Hey Wei
I know the basic way to popualte, but my case is that I don't know the Entity name a head, the function is generic dynamically, can I know by the type that I get the entity name?
use webapi to query the metadata. below is the sample, but you have to modify a little bit.
community.dynamics.com/.../retrieve-object-type-codes-via-webapi-url
https://community.dynamics.com/crm/f/117/t/218707
Hi ,
You need to pass entity name to populate the lookup which is mandatory . Seems you have objecttypecode so you can easily retrieve dynamically the entity name using web API.
Here is the web API query to retrieve the entity name.
xxxxxxxx.api.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,ObjectTypeCode&$filter=ObjectTypeCode eq 10026
You can refer below reference to know more about retrieve metadata using WebAPI.
https://msdn.microsoft.com/en-us/library/mt607522.aspx
Hope this helps.
Hey Goutam is that all the code I need? or should I use Sdk.request and set all request data, I tried using your code example and got errors..If I don't need the all code can you please add a full code example, I mean when I use the url on a browser I get my data but how do I use it on client side. insert in a var ?
Try with this , please change the version as per your CRM instance .
var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/EntityDefinitions?$select=LogicalName,ObjectTypeCode&$filter=ObjectTypeCode eq 10026", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { debugger; var result = JSON.parse(this.response); var logicalName = result["LogicalName"]; } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send();
Goutam, Thank you!
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2