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)

JavaScript to retrieve the all fields of an entity( for lead and opportunity)

(0) ShareShare
ReportReport
Posted on by

Hello all,

I have created an HTML web resource with a field called "Entity Selection" which is an OptionSet field with 2 values (Lead & Opportunity).
My requirement is :
Based on the "Entity Selection" field value I choose, I want all the fields of that selected entity to be listed/shown.
That is if I choose Lead as the value , I want all the fields of lead entity to be retrieved. Similarly for Opportunity as well.

Can anyone share me the JavaScript code for retrieving all the fields (display name) of a particular entity. 
Thanks in advance :)



*This post is locked for comments

I have the same question (0)
  • EmployeeOcta Profile Picture
    6 on at

    Hello Meharin,

    go through below url it will help you.

    https://msdn.microsoft.com/en-us/library/jj602964.aspx#BKMK_AccessingAttributes

  • Verified answer
    ThomasN Profile Picture
    3,190 on at

    Hi Meharin,

    Octa is right. Xrm.Page.getAttributes() blank will return all the attributes for an entity from a form.

    But you are trying to pull metadata rather than specific attributes that are loaded on a form. When using JavaScript in Online with Web resources you don't access context directly, you have to use the new Web API. [View:https://msdn.microsoft.com/en-us/library/gg490659.aspx:750:50]

    From the web resource you can access context using the GetGlobalContext function.

    [View:https://msdn.microsoft.com/en-us/library/gg328541.aspx#BKMK_GetGlobalContext:750:50]

    That will not help since your request is for an array of fields from variable chosen by the user, and that variable since it is on the web resource is out of context.

    Finally, you want the metadata not the values of those attributes. [View:https://msdn.microsoft.com/en-us/library/mt607522.aspx#bkmk_retrieveAttributes:750:50]

    • Here is an API call that will work. You then parse the results.
      • [organization url]/api/data/v8.2/EntityDefinitions?$select=DisplayName,EntitySetName&$filter=SchemaName%20eq%20%27Opportunity%27
      • This gives you the metadataID for the opportunity record in your CRM instance. Now use that value to create another API call and get the specific attributes for this.
    • Here is the next API call:
      • [organization url]/api/data/v8.2/EntityDefinitions(30b0cd7e-0081-42e1-9a48-688442277fae)?$select=LogicalName&$expand=Attributes($select=LogicalName)
      • Parse out the response.LogicalName into an array and display that as the options.
      • The response also provides the metadataId for specific reference when passing to context.

    Let me know if this helps.

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