Blog

Forms - How to append text to field in a data source

This post describes a solution to a question that occasionally arises - how to append text to a field when a user saves or edits a record through a form.

There's sometimes the requirement to append text to a field. A typical use case is to append text to a field for auditing purposes, or to maintain a history of previous entries. Another scenario is in cases where we store comma-separated values in a field and we want a simple way to append a single comma-separated value to the field.

This post describes how to carry out this task with a form.

Setting up a SharePoint data source to save historical changes to a field

For this example, we'll take the following SharePoint list of client details. This list contains two pertinent plain text fields -  Comment and CommentHistory.


The requirement for this example is as follows - when a user saves a record, the Comment field will be updated, and the text will also be appended to the CommentHistory field.

Appending text to a field when a user updates a record

The first step in this example is to take the edit screen from an auto-generated app and to ensure that the edit form includes both the comment and comment history fields.

To configure the form so that it appends the comment text to the comment history field, we set the Update property of the comment history card like so:

ThisItem.CommentHistory & " " & DataCardValue7.Text


Note here that DataCardValue7 refers to the text input control within the Comment card, NOT the text input control that belongs to the CommentHistory card.

As an adaptation, we can further customise the text that we append. For example, to append the current date and a line break, here's the formula we would use:

ThisItem.CommentHistory &  Char(10) & 
"Comment Date: " & Text(Now(), ShortDate) & Char(10) &
DataCardValue7.Text

Customising the form to hide the field

We may want to completely hide the comment history field from the user. In this case, we can set the visible property of the card to false. Note that when we set the visible property of a card to false, it makes it more difficult to locate the card in the designer. Therefore it's easier to carry out this task after we complete and test the form.



Alternatively, we may choose to display a read-only version of the comment history field to the user. In this case, we can add another card that binds to the CommentHistory field, and we can set the control type to "View text".

Conclusion

There are cases where it's necessary to append text to a field, usually for auditing purposes. This post described how to carry out this technique using a form.