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? 

  • cloflyMao Profile Picture
    25,208 on at
    RE: Retrieve most recently created contact using Javascript

    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

  • Mona Chavan Profile Picture
    255 on at
    RE: Retrieve most recently created contact using Javascript

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

  • ba365guy Profile Picture
    2,948 on at
    RE: Retrieve most recently created contact using Javascript

    Have you already written code and facing any issues?

    Or

    Are you looking for fresh code

  • Mona Chavan Profile Picture
    255 on at
    RE: Retrieve most recently created contact using Javascript

    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?

  • Suggested answer
    ba365guy Profile Picture
    2,948 on at
    RE: Retrieve most recently created contact using Javascript

    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 

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 32 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans