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)

Prepopulate default value (using metadata) of a Lookup

(0) ShareShare
ReportReport
Posted on by

Hi, there - I searched both communities but couldn't find anything (that worked). 

I am using the latest version of Microsoft CRM Portals.  I am looking to prepopulate a default value of a Lookup field using the Entity Form Metadata.   I tried setting the Value as the name of the value (UNSPECIFIED) as well as the GUID: 

Screen-Shot-2017_2D00_10_2D00_19-at-4.16.02-PM.png Tried "UNSPECIFIED"
Screen-Shot-2017_2D00_10_2D00_19-at-4.15.53-PM.pngTried the "GUID"
Screen-Shot-2017_2D00_10_2D00_19-at-4.15.38-PM.pngNot prepopulating on the Portal.

Neither worked in getting it to prepopulate on the portal as shown above.  For the record, I tried this feature with just regular text fields on the portal, and it works just fine.  It is the Lookup field I am having trouble with. 

Any input and/or solutions would be greatly appreciated.  Thanks!

Luke

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Prashant Wani Profile Picture
    441 on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Yes, I forgot to update. I was passing wrong GUID . Above code is working fine.

    Much better approach is ,

    $("#xyz_assigntoqueue_name").attr("value","Queue Support Team");

    $("#xyz_assigntoqueue").attr("value","b54403D96-ADE7-E611-80FE-5065F38BA511");

    $("#xyz_assigntoqueue_entityname").attr("value","queue");

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    1,835 on at
    RE: Prepopulate default value (using metadata) of a Lookup

    I can confirm that this approach works in multiple places in my latest-version portal.

    I assume you can have multiple reasons while you can't see this:

    - some plugin or workflow clearing out value

    - obvious (ID you have set is not correct then you can see this like working at the Portal UI, but not actually

    - the field is read-only ?

    - queues can have more hidden logic, than just select value on the form and save (probably some routing rules, queues eligibility, etc)

    - something else...

    Can you set the value inside the CRM on the same form and see it changed after the save ?

  • Prashant Wani Profile Picture
    441 on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Any solution anybody found?

  • Prashant Wani Profile Picture
    441 on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Its still not working on Save.

    It shows the value in lookup field on Load but when we save record it clears value. Please look at the code below

    $("#xyz_assigntoqueue_name").val("Queue Support Team");

    $("#xyz_assigntoqueue").val("b54403D96-ADE7-E611-80FE-5065F38BA511");

    $("#xyz_assigntoqueue_entityname").val("queue");

    I'm adding proper values  but still no luck , anybody has any solution over it?

  • Community Member Profile Picture
    on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Hi all, the javascript does still work but I have found that you have to be very precise with your data.  For example:

    $("#contact_name").val(namevalue);   <--- this must be the value of the first column that the lookup displays in it's results

    $("#contact").val(contactid);

    $("#contact_entityname").val("contact");

    Also, the lookup field MUST NOT be set to readonly.  If it is set to readonly in the form configuration then the form submit will ignore the values you populate.  I use jquery / css to hide or disable on page load instead.

    Hope this helps!!

  • Community Member Profile Picture
    on at
    RE: Prepopulate default value (using metadata) of a Lookup

    I am also looking for a solution to this.  I used to use the javascript solution but since upgrading to Portals 8 / 9 this has no longer worked.  Does anyone have a solution yet?  I will keep looking!

  • Ahmad Pirani Profile Picture
    90 on at
    RE: Prepopulate default value (using metadata) of a Lookup

    This JavaScript does not work anymore. At least not working on the downloaded ADX Portal source code. It does set the value, but it never gets picked up on Save. 

  • Community Member Profile Picture
    on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Thanks, Ravi.  I actually found that blog post shortly after posting my question.  It worked, FYI my code is as follows:

    $(document).ready(function(){

       $("#customerid_name").attr("value","UNSPECIFIED");

       $("#customerid").attr("value","c7ebf718-68b3-e711-8128-480fcfebc391");

       $("#customerid_entityname").attr("value","account");

    });

    However, if there is a non-javascript solution to this problem, I would still like to know!

    Thanks,

    Luke

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Prepopulate default value (using metadata) of a Lookup

    Hi Luke,

    It seems the prepopulate doesn't support setting the lookup values (It is only for static, date time or contact field values). This is an old thread from Adx Studio but looks still valid.

    community.adxstudio.com/.../7051ae7f-7308-e511-80fa-00155dc0a3d4

    You can check this article to achieve this using the JavaScript-

    arpitmscrmhunt.blogspot.com.au/.../adxstudio-set-values-in-lookup-fields.html

    '

    Hope this helps

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans