web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

{Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

(0) ShareShare
ReportReport
Posted on by 55,410 Moderator

Hi,

I have a web form which create the record for the 'Application' entity, I then have one more steps with a subgrid to the related child entity "Requests" i.e. 1 application can have more than 1 request. In this steps, I have added the metadata for the subgrid and added the create button which open the Entity Form for Create Request.

How would I pre populate the Application lookup on the qhile creating the Request record from the subgrid.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: {Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

    Hi Gaurav,

    When you create a record from a subgrid, it automatically gets associated with the main record on save.

    Hope this helps.

  • Gaurav_Pandey09 Profile Picture
    197 on at
    RE: {Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

    Hi Ravi,

    I do have a similar requirement where in I need to populate the lookup field in save and need not to show on the form.

    Can you please explain how did you relate the parent record with the grid settings?

  • Suggested answer
    Shan Mehdi Profile Picture
    on at
    RE: {Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

    Agreed with Ravi that this functionality is indeed OOB. Just wanna elaborate a bit more so that it's clear for anyone else experiencing this issue.

    The parent lookup field (in Ravi's case "Application") appears to be not pre-populating i.e. is empty when the popup opens up. However, if you remove the lookup field from the entity form and try to create the related record, the application id does get saved (in the background) and the record gets associated with the parent record i.e. "application".

    I think if you need to show the lookup pre-populated (which probably is a good idea) you would need to use the value from the parameters as explained in the other response.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: {Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

    Thanks Arpit. Thanks for sharing the above workaround.

    However, in my case, I observed that the lookup was populating by itself i.e. when user was adding the record in the subgrid, those records are automatically sets the parent look. I guess this is because in the subgrid i have used the the source as related record for the subgrid (I may be wrong).

  • Verified answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: {Dynamics 365 Portal} How to auto populate lookup on a create from a subgrid

     Hi Ravi,

    We also had the similar requirement but unfortunately, we couldn't find any OOB way to achieve this.

    I can suggest you one alternative solution, that I had tried to achieve this:

    1. Onload of Application Entity Form- Get the Application Record Guid (Can get it from the query string, see code below) and Application Record Name (Can get it from Application Entity Form itself). And then Store both the values in local storage/session. 

    Let say your Application Web page URL is:

    http://yourcrmportal.microsoftcrmportals.com/application-form/?id=599984bd-98a9-4a56-b9df-a78afb05f963

    // Get Id parameter value from query string
    function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }
    var applicationRecordGuid = getParameterByName('id'); // "id"

    See to get/set value in Local Storage:
    https://www.w3schools.com/html/html5_webstorage.asp

    2. Now onload of your subgrid record form (Request form), get the Guid from local storage and auto-populate it in the Application lookup field.

    $("attribute_name").attr("value","Name");
    $("arrtibute_id").attr("value","attribute_GUID");
    $("#attribute_entityname").attr("value","entity_name");

    Hope you understood.

    If you find the answer useful, please mark it as verified

    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

     

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans