Get Parent Record ID Using Dynamics 365 CRM Client API

By | October 15, 2020


There are a number of client APIs provided by Microsoft that helps developers work seamlessly with D365. One such useful method is getPageContext() in Xrm.Utility that can be used to get page context as an object representing the page. In this blog, we will see how we can use this method.

For an instance, I want to do some tasks on Quick Create Form of Account entity when I create a record of Account from Contact.

I have a function which is called onLoad of Account entity Quick Create Form, where I want to get some details of the parent records like the Contact Record ID, Name, etc. from where the Account record is going to be created and do further tasks.

To achieve the same, I have written a simple JavaScript function as shown below and called it on load of the Account Quick Create Form.

Note: This method is supported only on Unified Interface.

function onLoadAccountForm() {

try {

var pageContext = Xrm.Utility.getPageContext();

var input = pageContext.input;

var entityType = input.createFromEntity.entityType;

var recordId =;

var recordName =;

alert(“Entity: ” + entityType + ” recordId: ” + recordId + ” recordName: ” + recordName);

} catch (e) {




This method returns an object with the input property as shown below:

Get Parent Record Id Using D365 Client API

As I have called the function to get the record object on entity form, I am getting the pageType as “entityrecord” as shown in the above screenshot.

So, once the function gets triggered, I can use the Parent Record ID and other details to do my further tasks depending on the same.

We can also use this method to get the current displayed View ID and View Type along with the Entity Name and Page Type. Here, we will get the value for Page Type as “entitylist”.


Using this method we can get the page context to get the view details or records details and perform further tasks in our development.

70% of global 2000 companies apply gamification to improve productivity and returns!

Gamifics365 – Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!

3 thoughts on “Get Parent Record ID Using Dynamics 365 CRM Client API

  1. Surya

    i have a lookup on a quick create , on click of “new record” in this lookup opens a new quick create .Here i am trying to use the above mentioned function but not able to get any values in “createFromEntity” . Can you help me here

    1. Inogic

      Hi Surya,

      As you are not getting values in createFromEntity, you might not be getting the context of the parent record (1st quick create form record). We suggest that you check if the record is saving before opening the new quick create form from the previous one to get the context of the same.

      Hope that helps!

  2. Jai

    Does this require lookup of parent in quick create form. I am Not able to get data with this and what is 1st quick create form record..? I am trying to populate opportunity data on quick create of Opportunity close.

    Thank you.

Comments are closed.