Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

How to Query data in Dynamics 365

Posted on by Microsoft Employee

Hello guys,

I have this entitys: Client and Contacts.

In "Client" i have one lookup field of "Contacts".

In my Crm portals i have two lookups: 1- "Client" 2-"Contacts and i need to set the value of the lookup 2 with the value of the field "Contacts" of "Client".

I don't know how start the javascript.

How can I query this data?

Categories:
  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Query data in Dynamics 365

    Hi partner,

    Since it says "data is undefined", I recommend you to add "data" to "watch" column and monitor what is in "data", is it null or other data structure?

    Or may be you failed to call webapi and it returned error message.

    Hope it helps.

    Best Regards

    Leo

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to Query data in Dynamics 365

    In addition to above, if you value Contact value will always be set from the Client's Contact field then you can also hide the field in the portal and use Out of box workflow in CRM to populate the field value.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to Query data in Dynamics 365

    Hi,

    The code you shared is not correct. Your code to retrieve is also not correct and there are few other configuration/changes you need to do query the data. Also, you need to query the odata from portal url (not CRM). You can refer the below links for detailed steps-

    abhinavranjan.xyz/.../using-entity-list-as-odata-feed-dynamics-365-portal

    www.youtube.com/watch

    Once you configure the entity list, you can also try the below link to generate the odata query code-

    portalquerybuilder.netlify.com

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to Query data in Dynamics 365

    As suggested above please try to download CRMRestBuilder where you can create your query quickly without any error . Download it from here -

    github.com/.../CRMRESTBuilder

    Once you download the solution you need to import your CRM instance and do publish All customization. Refresh the page and go to settings --> Customization. In the ribbon you will find a button called CRMRestuilder just click on it , it will redirect to the tool .

    Select the entity which you want to retrieve data and add the filter with some hard coded value , then create query.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to Query data in Dynamics 365

    i can't paste a screenshot, but here is my code :

    $("customer").change(function(){    

           var name = $("#td_contadoendereco_name").val();

           var id = $("#td_contadoendereco").val();

           var entityname = $("#td_contadoendereco_entityname").val();

           if(ContaDoEndereco != null){

               var ODataUrl = "trialbdan.api.crm2.dynamics.com/.../td_conta$filter=td_contatosdacontaid eq '"+id+"'";

               $.ajax({

                   type: 'GET',

                   url: ODataUrl,

                   success: function (data) {

                       debugger;

                       if (data.value.length > 0) {

                           var ContaId = data.value[0]._td_conta_value;

                           //$("#parentcustomerid_name").attr("value","A J E CALDER LTD");

                           $("#parentcustomerid").attr("value",ContaId);

                           //$("#parentcustomerid_entityname").attr("value","contact");

                       }

                       else {

                           alert("sorry that address cannot be found");

                       }

                   },

                   error: function (jqXHR, textStatus, errorThrown) {

                       debugger;

                   }

               });

           }

    });

    When i debug the code shows that "data is undefined".

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Query data in Dynamics 365

    Hi partner,

    If you want to query data from CRM, I recommend to use WebApi provided by Microsoft.

    You could refer to samples of WebApi Query data and Get Start with WebApi.

    community6.PNG

    Hope it helps.

    Best Regards

    Leo

  • Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: How to Query data in Dynamics 365

    Can you try to paste a screenshot of what you want the value from where to where and what value? I can suggest how the JS code can come about.

    Hope this works.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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