You're right to question if there's a better solution than the one discussed five years ago, especially with the evolution of Dynamics 365 Marketing forms.
Good News: Yes, there have been significant improvements, and you can now directly achieve this within the Dynamics 365 Marketing form editor without relying on the older, more complex workarounds involving hidden fields and JavaScript for pre-population.
The Modern Solution: Using Lookup Fields and Default Values
The most straightforward and supported way to collect the Company (Account Name) and Job Title associated with a Contact filling out a Marketing form is by using Lookup fields and leveraging default values based on the contact record.
Here's how you can set up your form:
- Create the Form Fields:
- First Name: Use a standard Short text field and map it to the First Name (
firstname) field of the Contact entity. Mark it as Required.
- Last Name: Use a standard Short text field and map it to the Last Name (
lastname) field of the Contact entity. Mark it as Required.
- Email: Use a standard Email field and map it to the Email Address 1 (
emailaddress1) field of the Contact entity. Mark it as Required.
- Company: Use a Lookup field.
- Map to user input: Select Account (
account).
- Map to field: Choose the parentcustomerid field of the Contact entity.
- Default value: This is the crucial part. When configuring the Lookup field, you should see an option to set a Default value. You can configure this to "Prefill value" and then select "Contact" as the source entity and "Account Name" (
parentcustomerid.name) as the field to prefill from.
- Read-only: If you only want to display the company and not allow the Contact to change it, you can set the Read-only property of this Lookup field to Yes.
- Job Title: Use a standard Short text field.
- Map to user input: Select Contact (
contact).
- Map to field: Choose the Job Title (
jobtitle) field of the Contact entity.
- Default value: Similar to the Company field, set the Default value to "Prefill value", select "Contact" as the source entity, and "Job Title" (
jobtitle) as the field to prefill from.
- Read-only: If you only want to display the job title, set Read-only to Yes.
- Configure Form Settings:
- Ensure your form is set to "Update contacts/leads" on submit. This is usually the default behavior.
- Make sure the field mappings are correct so that the data entered by the Contact updates the corresponding fields on their Contact record.
Why This Works and is Better:
- Direct Mapping: You are directly mapping the "Company" Lookup field to the
parentcustomerid of the Contact. Dynamics 365 Marketing handles the relationship and display of the Account name.
- Prefill Values: The "Default value" option allows you to automatically populate the Company and Job Title fields with the existing data from the Contact record filling out the form. This happens when a known Contact (based on their browser cookie or email address matching an existing Contact) submits the form.
- No Custom Code: This solution is entirely configuration-driven within the Dynamics 365 Marketing form editor, eliminating the need for JavaScript or hidden fields.
- Supported Functionality: This leverages the intended features of Dynamics 365 Marketing forms for handling related entity data.
- Improved User Experience: Known Contacts will see their Company and Job Title pre-filled, making the form quicker to complete (or just review if the fields are read-only).
Addressing the "parentcustomeridname is read-only" Warning:
The warning message "Field parentcustomeridname is read-only and cannot be used in the form" likely appears if you try to directly add the parentcustomeridname field (the name of the related Account) as a direct input field on the form. This field is a calculated, read-only value that displays the name of the Account linked through the parentcustomerid lookup.
By using a Lookup field mapped to parentcustomerid and then utilizing the "Default value" to prefill the name from the related Account, you are correctly referencing the relationship and displaying the desired information without trying to directly use the read-only name field for input.
In summary, use Lookup fields for "Company" and "Job Title" and leverage the "Default value" option to prefill these fields with data from the Contact record. This is the modern, supported, and much simpler way to achieve your requirement in Dynamics 365 Marketing forms.