cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to append multiple columns to an existing colletion

casiguran.ev
Level 2

Say my collection 1 is column a column b column c column d and collection 2 is column a column b

I need to append column c and d to collection 2

is this possible and if so how?

2 REPLIES 2

steven.boggs
Staff
Staff

Have you tried using the 'Merge Collection' action in the Utility - Collection Manipulation VBO for this to see if it meets your requirements? In your example, you may need to first split the columns in the first collection you wish to merge into the second collection, but it should be possible based on the action's description:

"This merges two collections with different structures (and where the field names across both collections are unique) and forms a single collection with a combination of the two structures and associated data values.
Note: This field will fail if both collections contain any field names which are identical."

jacktian_opal
Level 2

If it's a common practice, then I'd say it is worth to have your customize code to do it. At least it is more than just common in my case.

Just so we are on the same page, collections are utilizing .net datatable(DataTable Class (System.Data) | Microsoft Learn), if you not familiar with it, have a check.

Therefore, the pseudocode would be something like.

DataTable input; // this is your collection 2 - as you pbly wanna keep the its data and change its structure.
DataTable template; // this is your collection 1 as you pbly dont need its data but need its structure.
boolean remove_excessive //optional, you can use this to control if you want to remove columns that are in input but not in the template.

foreach (column c in input.Columns)
	if (c is not in template.Columns && remove_excessive) 
		remove column c from input;

foreach (column c in template.Columns)
	if (c is not in Input.Columns)
		add column c to input; //you would need to new a col, set it up like c and add it tho