add a colum to a collection

sivagelli

Well-Known Member
Unless you want to deal with code, this is how you can achieve. Use 'Split Collection' action and split the collection into two.
Coll1 to have Field1 and other collection, Coll2 to have the remaining columns. Then, add a column to Coll1 using Append Field action and finally Merge the collections Coll1 & Coll2.
 

sivagelli

Well-Known Member
Alright! this can be helpful and quick in re-arranging the fields in a collection. To the Collection you have append a column using "Append Field (text)" or "Append Field (Number)" based on your requirement of field data type. The field will be added to the collection at the end. Now, use the below code to re-arrange the order of the fields in collection.

This is C# code.

Add this code in the Global Code of an object -

C#:
public static DataTable SetColumnsOrder(DataTable table, params String[] columnNames)
{
        int columnIndex = 0;
        foreach(var columnName in columnNames)
        {
            table.Columns[columnName].SetOrdinal(columnIndex);
            columnIndex++;
        }
        return table;
}

Add a code stage with
  • input arguments:
    • Coll_Input (type Collection)
    • FieldsOrder (type Text)
  • output arguments:
    • Coll_Out

Add the below code in the Code tab-

Code:
string[] reFields = FiledsOrder.Split(new[]{","}, StringSplitOptions.None);
Coll_Out = SetColumnsOrder(Coll_Input, reFields  );

You have to pass the input collection and the fields order in a comma separated format. On execution, the Coll_Out will have the rearranged fields.

Post back how it goes!
 
Last edited:

CD58

New Member
Alright! this can be helpful and quick in re-arranging the fields in a collection. To the Collection you have append a column using "Append Field (text)" or "Append Field (Number)" based on your requirement of field data type. The field will be added to the collection at the end. Now, use the below code to re-arrange the order of the fields in collection.

This is C# code.

Add this code in the Global Code of an object -

C#:
public static DataTable SetColumnsOrder(DataTable table, params String[] columnNames)
{
        int columnIndex = 0;
        foreach(var columnName in columnNames)
        {
            table.Columns[columnName].SetOrdinal(columnIndex);
            columnIndex++;
        }
        return table;
}

Add a code stage with
  • input arguments:
    • Coll_Input (type Collection)
    • FieldsOrder (type Text)
  • output arguments:
    • Coll_Out

Add the below code in the Code tab-

Code:
string[] reFields = FiledsOrder.Split(new[]{","}, StringSplitOptions.None);
Coll_Out = SetColumnsOrder(Coll_Input, reFields  );

You have to pass the input collection and the fields order in a comma separated format. On execution, the Coll_Out will have the rearranged fields.

Post back how it goes!
Very Helpfull thank you
 
Top