Blog
Forms - How to append text to field in a data source
February 10. 2022
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.
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:
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.
ThisItem.CommentHistory & " " & DataCardValue7.Text
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.- Categories:
- forms
Related posts
- Forms - How to set the value of a field to todays date for new records only
- Apps - How to create an app from a hand drawn image
- Forms - How to highlight user modified field values on a form
- Forms - How to calculate values (eg sums and products) and store the results in SharePoint or other datasource
- SharePoint - How to programmatically set and clear single select choice items in a combo box on a form
- SharePoint - How to clear datetime fields/set an empty datetime value on a form
- Forms - How to convert a display form to an edit form
- Forms - How to copy/save an existing record on a form as a new record
- Forms - How to show Office 365 user profile details on a form
- Forms - How to hide fields that are blank, or have not been completed
- Forms - How to select-all / unselect-all checkbox or toggle controls on a form
- Forms - How to set the data source of a form to a collection
- Forms - The best practice for setting the data item on a form
- Controls - How to set default control and form values
- Forms - How to conditionally make form fields mandatory