DEV Community

Cover image for Enhancing Comment History Functionality in Power Apps
Rick Hurt
Rick Hurt

Posted on

Enhancing Comment History Functionality in Power Apps

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.

Append Comment History in SharePoint

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.

Create multiline text field

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.

Basic Power App

Adding Comment History Functionality

In the Edit Screen, I made the following modifications:

  1. I added a Custom Card to include a new comment section. Added a text box for entering comments.
  2. Inserted a βž• button for adding comments to the comment history.
  3. Adjusted the size of the Comment History text box to accommodate multiple comment histories and changed its mode to "multiline."
  4. Set the display mode of the comment history to "Disabled" so that users can't directly edit it.
  5. 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)
Enter fullscreen mode Exit fullscreen mode

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()})

Form updates

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.
Finished app

Top comments (0)