Saving a collection of data

When a layout shows a collection of data, the collection is available within the current context by using the Items property. You can access any of the properties and unbound component values that are associated with each item in the collection. Header components that are not associated with any record are available through the UnboundComponents property in the context.

If data has been modified and you want to save it back to the data source, use the SaveChanges API, as shown in this example:


Dim result As IPFItemValidationResultI = context.Items(index).SaveChanges()
If result.IsValid = False Then
... do something with result.Message...
End If
If result.SaveCompleted = False Then
... do something with result.Message...
End If

When this API is run, first it invokes the ItemValidating event handler to validate the record. During validation, the handler can return messages about the record and/or about each property. If the event handler marks the record as invalid, the save to the data source is not attempted.

If multiple records have been modified, the script can save all of them, as shown in this example:


Dim results As IPFItemValidationResultI() = context.Items.SaveChanges()
For Each result As IPFItemValidationResultI In results
   If result.IsValid = False Then
      ... do something with result.Message...
   End If
   If result.SaveCompleted = False Then
      ... do something with result.Message...
   End If
Next

In either case (single record save or multiple save), the records are saved one by one to the data source. There is no functional difference between these methods at the data source level. With a multiple save, some records could save successfully while others could fail during validation or during the save to the data source.