I have a canvas app that uses a SharePoint list for the data source. On the Home screen, the user selects one or more checkboxes to determine what content will be included on the form. Checking and unchecking the checkboxes adds and removes that item from the 'HmCheckboxStates' collection.
- I add items to the 'HmCheckboxStates' collection one at a time when the user checks a checkbox.
- I remove items one at a time when the user unchecks a checkbox.
- As long as at least one item exists in the 'HmCheckboxStates' collection, I allow the user to submit these selections which in turn I use the Patch function to create a new record in the 'DS PreOp Insp Jobs' SharePoint list.
- The 'HmCheckboxStates' collection has three columns: 'ListCol', 'Name', and 'Value'.
- 'ListCol' is the actual column name in the SharePoint list.
- 'Name' is the name of the checkbox (e.g., 'checkboxSkidSystem1')
- 'Value' will be T/F based on the state of the checkbox
- 'ListCol' is the name of the corresponding column in the 'DS PreOp Insp Jobs' SP list.
//Example: 'checkboxSkidSystem1' checkbox
// OnCheck
Collect(HmCheckboxStates, {Name: "checkboxSkidSystem1", Value: checkboxSkidSystem1.Value, ListCol: "Skid System 1"})
// OnUncheck
Remove(HmCheckboxStates, LookUp(HmCheckboxStates, Name = "checkboxSkidSystem1"))
I need to use the Patch function to create a new record in the 'DS PreOp Insp Jobs' SP list so I am looking at how would I loop through all items in the 'HmCheckboxStates' collection to update the corresponding column. For example, if 'checkboxSkidSystem1' is checked, then I need to create a new record and the 'Skid System 1' column (a Yes/No col type) needs to be saved as a Yes. The same goes for any other items in the 'HmCheckboxStates' collection.
// I need to add code to include the 'HmCheckboxStates' checkbox collection items to this code
Patch(
'DS PreOp Insp Jobs',
Defaults('DS PreOp Insp Jobs'),
// Include the 'JobName' and 'Inspection Date Start' fields
{
'JobName': "PreOp-" & Text(Now(), "[$-en-US]yyyy-mm-dd hh:mm:ss"),
'Inspection Date Start': Now()
}
);
What is best for looping through the 'HmCheckboxStates' collection and setting the respective columns to Yes while allowing other columns in the destination SP list be updated?