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?
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?
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
No i have not written any code i dont know which approach to go for
Have you already written code and facing any issues?
Or
Are you looking for fresh code
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?
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
Siv Sagar
149
Super User 2025 Season 1
Daivat Vartak (v-9d...
53
Super User 2025 Season 1
Vahid Ghafarpour
32
Super User 2025 Season 1