Hello guys,
I had a collection and i want to add a column into it: between Field 1 and 2
View attachment 1550501242138.png
I had a collection and i want to add a column into it: between Field 1 and 2
View attachment 1550501242138.png
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;
}
string[] reFields = FiledsOrder.Split(new[]{","}, StringSplitOptions.None);
Coll_Out = SetColumnsOrder(Coll_Input, reFields );
Very Helpfull thank youAlright! 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!