Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

How can I pre-populate a form choice field in a Portal?

I am working on a Portal where Contacts associated with an Account should be able to add another Contact - but only to the same Account.

All Contacts are Authenticated users in the Portal. I have created a form where the authenticated user can create a Contact. In this form, the user has to select the Account to associate with the Contact, although the only Account available for selection is the authenticated user's account, as in the attached image.


This is error prone. For usability, I would like (OK, need!) the correct Account to be pre-selected in the Account Choice. Ideally in fact I would like the user to be unable to edit this field at all.


While it is comparitively easy to pre-populate a Basic Form text field using a snippet of JavaScript, I cannot see how to do this successfully for a Choice. (Note that I can use JavaScript to add text to the Choice, but of course this is not the same as selecting the appropriate value in the Choice field!)


Solution Sage
Solution Sage

(note: the Account field is a Lookup not a choices field )


If the Account is the same as the Account that the currently logged in user belongs to then I would probably not display the field and set it via the Form's MetaData (see the metadata On Save - to set the Lookup to the the corresponding Lookup field on the logged in Contact record).

(edit: you should also be able to prepopulate using the Prepopulate field see that same link)


If you need to use JavaScript then Lookup fields are set in a similar way but requires the internal GUID and additional values, there is also a slight difference if the Lookup is a Customer or Account Lookup - for a Customer Lookup the last line in the below is required (as the Customer Lookup accepts both contact and account).  












Frequent Visitor

Thanks, @Fubar . It turns out I wasn't able to use the Basic Form Metadata to set the value on the Lookup, but I could use it without difficulty to set a number of the text fields on the form, so it was still very useful!

I was able to resolve my problem using JavaScript as you suggest:


var accountName = '{{ user.parentcustomerid.Name }}';
var accountId = '{{}}';

$( "#parentcustomerid" ).val( accountId );
$( "#parentcustomerid_name" ).val( accountName );


For anyone else looking for an answer to a similar problem, I should note that this does not work if I disable the actual #parentcustomerid in JavaScript - I had to disable the buttons for clearing the lookup and for opening the lookup in JavaScript instead.

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel News & Announcements 768460.png

What's New in the Community?

Check out the latest News & Events in the community!

MPP IDEAS updated 768x460.png


Discover ideas and concepts from users like you for how to use Power Pages and take your work to the next level.

Top Solution Authors
Users online (4,403)