Blog
Forms - How to set the data source of a form to a collection
It can be difficult to build edit forms that are based on collections, because the designer disables the button to add fields to the form. This post describes this behaviour, and explains how we can configure an edit form to save and update rows in a collection.
Overview of problem
Let's suppose we define a collection with the formula beneath.
ClearCollect(colAddresses,
{
Firstname:"Tim", Surname:"Leung",
Address1:"1 High Street", City:"London"
}
)
Next, we add an edit form and use the 'Data source' dropdown to set the data source to our collection (colAddresses).
If we now click the 'Edit fields' link, the 'Add field' button is grayed out, as shown in the screenshot beneath. This makes it impossible to create cards that based on the fields in the collection.
It's possible to add a custom card. However, the limitation of a custom card is that it does not expose an update property. As the screenshot beneath shows, the update property is missing from the card.
Workaround of problem
We set the data source of the form to the connected data source. From here, we can now add cards to the form. The cards that we add will include the update property, as shown beneath.
Once we complete the design of our form, we can change the data source back to collection that we want to use. As the screenshot beneath shows, we can set the item property to a record in the collection and the form will correctly display the record.
Although the form control still displays the message "This form isn't connected to any data yet - Connect to data", it will still edit the record as expected.
Conclusion
Note that if we don't want to go to the effort of creating a new data source with fields that match the collection, we can set the data source of the form to any connected data source, and to amend the DataField, DisplayName, Default, and Update properties as required.
- Categories:
- forms
- 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 append text to field in a data source
- 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 - 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