Auto-populate contact lookup as current portal login user on record create from power page or portal using form Associated Table Reference configuration no code
Sometimes there is a business need that you need to create a Dataverse record which contains a contact lookup.
For example the below form contains a lookup field Patient. Here for my case Contact entity display name is Patient.
The business need is, when a new record is created using above form, the Patient lookup which is actually pointing to contact entity must be auto saved using current portal user login so that user should not select the value manually.
For this we have to follow the below steps.
Step 1 : Configure Associated Table Reference configuration
Open the form which needs to update. For my case, its Create Record Form. Navigate to the form and select Tab Associated Table Reference.
Provide the below options:
Set Table Reference On Save | Yes |
Table Name | Contact (for my case display name is patient) |
Relationship Name | Select the relationship name from dropdown which is associated with current entity |
NOTE : Important | At this time save the for so that the Target Attribute Lookup Logical Name field will enable. |
Target Attribute Lookup Logical Name | Select the lookup field to auto saved |
Populate Lookup Field | Enable the checkbox |
In Table Reference source subgrid select Source Type as Record Associated to current Portal User and in Record Source Relationship name select Master ID from drop down.
Step 2 : Add Metadata (This will only used for Text Fields)
On the Form, Navigate to Basic Form Metadata and add a new Basic Metadata of type attribute and select field Patient from the drop down.
Scroll down the metadata form to select Prepopulate Field. Enable ignore Default Value, Type as Current Portal user, Form Attribute as contact lookup for me its Patient.
Next navigate to Set Value On Save section and configure as below.
Step 3 – Enable Additional Settings (For Lookup)
In the Additional Settings Tab, go to Associate Current Portal user on Insert section and enable Associated Current Portal User option and select the contact lookup from the column dropdown.
Done !!!
Now save the changes and clear the cache memory or in power pages studio, click Sync button and then click Preview.
Now if you save the form with patient lookup blank, the record will be saved with the patient lookup as current login user.
Test:
First fill the form without patient lookup. click Submit.
On Submit click the form will be saved and will save the current login user lookup in the record.
Hope this helps.