Enhancing Comment History Functionality in Power Apps
Rick Hurt
Posted on November 6, 2023
When working with SharePoint Online lists, it's easy to create a multi-line text field to capture comments and comment history for line items. SharePoint leverages version control to store and display these comments on your edit or display fields.
However, when it comes to working with version history in Power Apps, things can get tricky. In this post, we will explore an alternative way to simulate this functionality using a multi-line text field. This approach can be applied not just in SharePoint but also in Dataverse, SQL, or other data sources.
Setting Up the Multi-Line Text Field
Start by creating a SharePoint list column with the data type set to "Multi-line" and configure it as plain text. Ensure that you do not select the "Append changes to existing text" option in the column settings.
Creating a Power App
For this demonstration, I've created a basic Power App with CRUD (Create, Read, Update, Delete) operations, and these operations are set up using the SharePoint integration feature.
Adding Comment History Functionality
In the Edit Screen, I made the following modifications:
- I added a Custom Card to include a new comment section. Added a text box for entering comments.
- Inserted a ➕ button for adding comments to the comment history.
- Adjusted the size of the Comment History text box to accommodate multiple comment histories and changed its mode to "multiline."
- Set the display mode of the comment history to "Disabled" so that users can't directly edit it.
- For the ➕ icon's OnSelect action, you can add the following code. This code can also be added to your Form save button if you prefer not to have a separate button for adding comments:
If(
!IsBlank(txtAddComment.Text),
UpdateContext(
{
varLocalCommentHistory: $"{User().FullName} ({Text(
Now(),
DateTimeFormat.ShortDateTime
)}): {txtAddComment.Text}{Char(13)} {txtCommentHistory.Text}" // Char(13) gives you a line break between comments
}
)
);
Reset(txtAddComment)
6.On your comments card, in the Default property, you can add the following code:
If(!IsBlank(varLocalCommentHistory), varLocalCommentHistory, ThisItem.'Comments History')
7.In the ResetForm property of your form, you can add the following code:
UpdateContext({varLocalCommentHistory:Blank()})
The finished app provides a seamless way to capture and display comment history for line items. This approach is versatile and can be applied to various data sources, making it a valuable addition to your Power Apps toolkit.
Posted on November 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.