Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

Posted on by 55,410

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

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 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
    Gaurav_Pandey09 195 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
    Shan Mehdi 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
    RaviKashyap 55,410 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
    Arpit Shrivastava 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans