Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How can i create attribute in existing Entity using javascript?

Posted on by 120

I want to add an attribute to an existing entity using Java Script.

For this i also want to get list of entities in a dropdown of my UI such that i can select an entity and add attributes to the selected entity.

Please provide me solution.

Thanks in Advance.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can i create attribute in existing Entity using javascript?

    Vaibhav,

    Download Rest Builder for dynamics 365 and import it to the CRM Instance and refresh it.

    When you click on the rest builder button it opens in a new tab with requirements what you just requested for !....

    Thanks..

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How can i create attribute in existing Entity using javascript?

    Hi,

    You could use Web API in Javascript to retrieve all the entity Display names in Dynamics CRM. You could use the following URL in the XMLHttpRequest in Javascript for calling the Web API to retrieve all the entities. 

    https://msdn.microsoft.com/en-in/library/mt607522.aspx#bkmk_QueryingEntityMetadata

    For examples of consuming Web API in javascript, see the link below.

    https://msdn.microsoft.com/en-in/library/gg334279.aspx#bkmk_usingXHR

    Use the code below. Here we use GET method.

    var req = new XMLHttpRequest();
    req.open("GET",encodeURI(clientURL + "/api/data/v8.2/EntityDefinitions?$select=LogicalName,DisplayName"), 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) {
      req.onreadystatechange = null;
      if (this.status == 200) {
       var result = JSON.parse(this.response);
       //Write the logic to set the value to the dropdownlist by looping through this response
    //Set the value of the option in the drop-down list as LogicalName and text as DisplayName.
    }
    else {
    var error = JSON.parse(this.response).error;
    console.log(error.message);
    }
    }
    };
    req.send(JSON.stringify({ name: "Sample account" }));

    In order to create attributes in the entity, you could use the following Web API URL and use the POST method in XML HTTP Request.

    See: https://msdn.microsoft.com/en-in/library/mt593078.aspx#bkmk_CreateAttributes

    Hope this helps.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How can i create attribute in existing Entity using javascript?

    You can use the webapi for your requirements.

    To get the list of your entities, you can use the RetrieveAllEntities web api function call.

    msdn.microsoft.com/.../mt683536.aspx

    The following link demonstrates how to Create an Attribute using web api.

    msdn.microsoft.com/.../mt593078.aspx

    You will need to use the Entity Definitions api call with the Entity Id and the Create Request for the attribute.

    There are some api helper tools available if you need.

    One of the recommended ones is XrmTools CRMWebApi from David Yack:

    github.com/.../Xrm.Tools.CRMWebAPI

    Hope 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans