UpdateCollection
The UpdateCollection method modifies a collection (inserting, updating, or deleting
records) using the UpdateCollection method of an IDO.
Example 1 – Basic Insert, Update, and Delete operations using UpdateCollection
This example code shows how you can perform different actions for each row in the collection within a single request. This request creates a new user, updates the description of user wsmith, and deletes the record of user cdelune.
Client client = new Client( requestServiceURL, IDOProtocol.Http ); UpdateCollectionResponseData response = default( UpdateCollectionResponseData ); using ( client ) { // item to insert IDOUpdateItem inserItem = new IDOUpdateItem( UpdateAction.Insert ); inserItem.Properties.Add( new IDOUpdateProperty( "Username", "jdoe", true ) ); inserItem.Properties.Add( new IDOUpdateProperty( "UserDesc", "John Doe", true ) ); // item to update IDOUpdateItem updateItem = new IDOUpdateItem( UpdateAction.Update, "PBT=[UserNames] UserNames.DT=[2019-08-15 17:30:09.870] UserNames.ID=[b3aedc23-722f-4058-b12c-f14bdfd955b4]" ); inserItem.Properties.Add( new IDOUpdateProperty( "UserDesc", "Will Smith Sr.", true ) ); // item to delete IDOUpdateItem deleteItem = new IDOUpdateItem( UpdateAction.Delete, "PBT=[UserNames] UserNames.DT=[2019-08-15 17:30:52.253] UserNames.ID=[018ae411-42c3-48cb-a50b-b943dcb70dbe]" ); IDOUpdateItems updateItems = new IDOUpdateItems() { inserItem, updateItem, deleteItem }; UpdateCollectionRequestData request = new UpdateCollectionRequestData() { IDOName = "UserNames", Items = updateItems, RefreshAfterUpdate = true }; response = client.UpdateCollection( request ); // Updated IDO items can be enumerated as follows foreach ( IDOUpdateItem item in response.Items ) { // Do something... foreach ( IDOUpdateProperty property in item.Properties ) { Console.WriteLine( property.Value ); } } }
Example 2 – Nested update collection operations
This is an example code for a nested or hierarchical request. This request inserts a user-defined type and its value in a single request.
Client client = new Client( requestServiceURL, IDOProtocol.Http );
UpdateCollectionResponseData response = default( UpdateCollectionResponseData );
using ( client )
{
// Create an UpdateCollection request for the child IDO
IDOUpdateItem userDefTypeVal = new IDOUpdateItem( UpdateAction.Insert );
userDefTypeVal.Properties.Add( new IDOUpdateProperty( "TypeName", "Month", true ) );
userDefTypeVal.Properties.Add( new IDOUpdateProperty( "Value", "January", true ) );
IDOUpdateItems userDefTypeValItems = new IDOUpdateItems() { userDefTypeVal };
UpdateCollectionRequestData userDefTypeValRequest = new UpdateCollectionRequestData
{
IDOName = "UserDefinedTypeValues",
RefreshAfterUpdate = true,
Items = userDefTypeValItems
};
// Set the relationship data of the child and parent IDOs
userDefTypeValRequest.SetLinkBy( "Name", "TypeName" );
// Create an UpdateCollection request for the parent IDO
IDOUpdateItem userDefType = new IDOUpdateItem( UpdateAction.Insert );
userDefType.Properties.Add( new IDOUpdateProperty( "Description", "An amount of time used with calendars", true ) );
userDefType.Properties.Add( new IDOUpdateProperty( "Name", "Month", true ) );
// Nest the user emails LoadCollection request inside the user LoadCollection request
userDefType.AddNestedUpdate( userDefTypeValRequest );
IDOUpdateItems userDefTypeItems = new IDOUpdateItems() { userDefType };
UpdateCollectionRequestData userDefTypeRequest = new UpdateCollectionRequestData
{
IDOName = "UserDefinedTypes",
RefreshAfterUpdate = true,
Items = userDefTypeItems
};
response = client.UpdateCollection( userDefTypeRequest );
// Updated IDO items can be enumerated as follows
foreach ( IDOUpdateItem item in response.Items )
{
// Do something...
foreach ( IDOUpdateProperty property in item.Properties )
{
Console.WriteLine( property.Value );
}
}
}