You've spent time carefully crafting your Dataverse Forms and Basic Forms, and then applied them to Web Pages within your Power Pages site. While testing out your forms, you've noticed that the rows stored in Dataverse don't contain the Contact who created or modified these rows. Instead, you notice that the Created By and Modified By columns contain something like "# Your-Site-Name".
Why is that?
Out of the box, the Created By and Modified By columns on a table do not capture this information since those columns are lookups to Users, not Contacts. Remember, Contacts are your authenticated Power Pages users, and are stored in their own separate Dataverse table.
How do we capture the proper Contact?
Perhaps you have table permissions in place to where a Contact can view and edit rows that they have created along with rows that are related to their parent Account. A common business scenario is to be able to track what Contact is making changes to a row through your Power Pages site. The first thing you'll need to do is create 2 lookup columns on the table in question that point to the Contact table. One will be for the Contact who created the row, and one will be for the Contact who last modified the row.
Next, we'll navigate to the Portal Management application and take a look at our Basic Forms.
Track Creation
For row creation, open the Basic Form that is set to Insert mode. Then, navigate to the Additional Settings tab. Scroll down to the section that is labeled Associate Current Portal User on Insert.
Check the box for Associate Current Portal User and then select the lookup column that has been created to capture the Contact that created the row. From my example, I'll be selecting the column labeled Created By (Contact).
Track Modification
For row modification, open the Basic Form that is set to Edit mode. Then, navigate to the Basic Form Metadata tab and click + New Basic Form Metadata. Set Type to Attribute and then set the Attribute Logical Name to the column that you have created to contain the Contact that most recently modified the row. For my example, I'll be selecting the column labeled Modified By (Contact).
Scroll down to the section labeled Set Value on Save. Check the box for Set Value On Save and set the Type to Current Portal User. Set From Attribute to Contact (contactid).
Results
After implementing these changes, I can now see the Contact who has created or modified a row, and when. Next, you can add these lookup columns on your various Dataverse forms or views to display the Contact in your Power Pages site, Model-Driven App, and more!
//Tech Tip: The custom columns that you have created do not need to be added to the forms or views in order to set or update this data.
*This post is locked for comments