Mapping parent lookup fields when using navigate in Dynamics CRM 2015

Ahmed Anwar, 15 December 2015

One of our customers wanted to create multiple forms for a custom entity and automatically redirect the user to the correct form based on a certain field value. Microsoft already has introduced the navigate() method since version 2011.

Unfortunately in CRM 2015 version 7.0, the navigate function does not retain field mappings when opening a form from a parent entity (N:1), which means if you save the child record after the redirection, the child record will be an orphan.

For example, you create multiple forms for the Opportunity entity. From the Account record, you create a new opportunity using a sub-grid or the associated grid. The Customer lookup field on the opportunity automatically links/maps to the Account record. However, if you call navigate(), that lookup field will lose the mapping to the parent Account.

To resolve this problem, you need to add a few extra lines to correctly map to the parent record:


As you can see, window.parent.opener contains the Xrm object of the parent entity. Now you have all necessary information to construct a lookup reference and set the lookup field on the child record.

IMPORTANT: accessing the window object as you saw above is not supported by Microsoft, so you have to be careful.