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 365 | Integration, Dataverse...
Suggested Answer

Retrieve most recently created contact using Javascript

(0) ShareShare
ReportReport
Posted on by 255

Hi All,

I have one form of account entity.

on account record i have sub grid of contact entity.

i need to retrieve the most recently created contact .

can i do this using javascript in CRM 365 9.0? 

I have the same question (0)
  • Suggested answer
    ba365guy Profile Picture
    2,950 on at

    Are you trying to retrieve most recently created contact in general OR most recently created contact for that particular account (which is already listed in sub-grid)? 

    In either of the cases, you can retrieve this using javascript api 

  • Mona Chavan Profile Picture
    255 on at

    i am Retrieving most recently created contact for that particular account and that i am populating on another form after clicking on one button on ribbon.

    can you share link or code for reference?

  • ba365guy Profile Picture
    2,950 on at

    Have you already written code and facing any issues?

    Or

    Are you looking for fresh code

  • Mona Chavan Profile Picture
    255 on at

    No i have not written any code i dont know which approach to go for

  • cloflyMao Profile Picture
    25,210 on at

    Hi Mona,

    Try following code (and run it on your ribbon button) to get most created contact record under current account in Account form:

    var currentAccount = Xrm.Page.data.entity.getId().replace('{','').replace('}','');
    
    Xrm.WebApi.retrieveMultipleRecords("contact", "?$select=fullname,createdon&$top=1&$filter=_parentcustomerid_value eq '"   currentAccount   "'&$orderby=createdon desc").then(
        function success(result) {
            for (var i = 0; i < result.entities.length; i  ) {
                // console.log(result.entities[i]);
                // result.entities[i]["fullname"];
            }                    
        },
        function (error) {
            console.log(error.message);
        }
    );

    My code is based on client API: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrievemultiplerecords

    You can also generate CRUD code automatically with CRMRestBuilder:

    https://github.com/jlattimer/CRMRESTBuilder(an icon will appear in settings > customization after you've imported the solution)

    You could take article below as reference for how to add a ribbon button:

    https://dynamicscrmtips.com/button-dynamics-crm-ribbon-workbench/

    Regards,

    Clofly

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans