Enhancing Comment History Functionality in Power Apps
Tags: powerplatform, powerapps, sharepoint, powerfx
Published: 2023-11-06 18:03:20

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebegj92zzzess0s3ktbo.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmaqj8kwgutk4kp0k65b.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tzfjfgb3i1of8i49snc.png)

## 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)
```
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0dvzenm2jc2pt2q6b8h.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsis4wa10u1kos3zu8eh.png)