Need to know how to sort a list or a dataitem list ?
the list.sort() syntax doesn't seem to work in workflow and I cannot see any other functions that would sort a list of strings. Would it be possible to use the vb script or c# script or possibly invoke method to sort a string list. Of course, I would like a sample of the code or method to do this.
J
-
Hi Jeff,
I ran across this post, and was curious myself so I gave it a try in this little workflow. Looks like you'll need to use the invoke method to make it work.
-Kev
<Activity mc:Ignorable="sap sads" x:Class="{x:Null}" sap:VirtualizedContainerService.HintSize="349,1752" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:eac="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client" xmlns:eacg="clr-namespace:ESRI.ArcGIS.Client.Geometry;assembly=ESRI.ArcGIS.Client" xmlns:eact="clr-namespace:ESRI.ArcGIS.Client.Tasks;assembly=ESRI.ArcGIS.Client" xmlns:gce="clr-namespace:Geocortex.Core.Extensions;assembly=Geocortex.Core" xmlns:gfc="clr-namespace:Geocortex.Forms.Client;assembly=Geocortex.EssentialsWpfApi" xmlns:gfci="clr-namespace:Geocortex.Forms.Client.Items;assembly=Geocortex.EssentialsWpfApi" xmlns:gr="clr-namespace:Geocortex.Reporting;assembly=Geocortex.Reporting" xmlns:gwa="clr-namespace:Geocortex.Workflow.Activities;assembly=Geocortex.Workflow" xmlns:gwa1="clr-namespace:Geocortex.Workflow.Activities;assembly=Geocortex.Workflow.Activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=System.Core" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=mscorlib" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Sequence sap:VirtualizedContainerService.HintSize="309,1672" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"> <Sequence.Variables> <Variable x:TypeArguments="scg2:List(x:String)" Default="[New List(Of String)]" Name="stringList" /> <Variable x:TypeArguments="x:String" Name="sortedString" /> <Variable x:TypeArguments="x:String" Name="unsortedString" /> </Sequence.Variables> <sap:WorkflowViewStateService.ViewState> <scg2:Dictionary x:TypeArguments="x:String, x:Object"> <x:Boolean x:Key="IsExpanded">True</x:Boolean> </scg2:Dictionary> </sap:WorkflowViewStateService.ViewState> <InvokeMethod sap:VirtualizedContainerService.HintSize="287,128" MethodName="Add"> <InvokeMethod.TargetObject> <InArgument x:TypeArguments="scg2:List(x:String)">[stringList]</InArgument> </InvokeMethod.TargetObject> <InArgument x:TypeArguments="x:String">Z</InArgument> </InvokeMethod> <InvokeMethod sap:VirtualizedContainerService.HintSize="287,128" MethodName="Add"> <InvokeMethod.TargetObject> <InArgument x:TypeArguments="scg2:List(x:String)">[stringList]</InArgument> </InvokeMethod.TargetObject> <InArgument x:TypeArguments="x:String">D</InArgument> </InvokeMethod> <InvokeMethod sap:VirtualizedContainerService.HintSize="287,128" MethodName="Add"> <InvokeMethod.TargetObject> <InArgument x:TypeArguments="scg2:List(x:String)">[stringList]</InArgument> </InvokeMethod.TargetObject> <InArgument x:TypeArguments="x:String">A</InArgument> </InvokeMethod> <InvokeMethod sap:VirtualizedContainerService.HintSize="287,128" MethodName="Add"> <InvokeMethod.TargetObject> <InArgument x:TypeArguments="scg2:List(x:String)">[stringList]</InArgument> </InvokeMethod.TargetObject> <InArgument x:TypeArguments="x:String">Y</InArgument> </InvokeMethod> <ForEach x:TypeArguments="x:String" DisplayName="ForEach<String>" sap:VirtualizedContainerService.HintSize="287,208" Values="[stringList]"> <ActivityAction x:TypeArguments="x:String"> <ActivityAction.Argument> <DelegateInArgument x:TypeArguments="x:String" Name="item" /> </ActivityAction.Argument> <Assign sap:VirtualizedContainerService.HintSize="242,60"> <Assign.To> <OutArgument x:TypeArguments="x:String">[unsortedString]</OutArgument> </Assign.To> <Assign.Value> <InArgument x:TypeArguments="x:String">[unsortedString + " " + item]</InArgument> </Assign.Value> </Assign> </ActivityAction> </ForEach> <gwa1:Alert sap:VirtualizedContainerService.HintSize="287,86" Text="[unsortedString]" Title="Unsorted" /> <InvokeMethod sap:VirtualizedContainerService.HintSize="287,128" MethodName="Sort"> <InvokeMethod.TargetObject> <InArgument x:TypeArguments="scg2:List(x:String)">[stringList]</InArgument> </InvokeMethod.TargetObject> </InvokeMethod> <ForEach x:TypeArguments="x:String" DisplayName="ForEach<String>" sap:VirtualizedContainerService.HintSize="287,208" Values="[stringList]"> <ActivityAction x:TypeArguments="x:String"> <ActivityAction.Argument> <DelegateInArgument x:TypeArguments="x:String" Name="item" /> </ActivityAction.Argument> <Assign sap:VirtualizedContainerService.HintSize="242,60"> <Assign.To> <OutArgument x:TypeArguments="x:String">[sortedString]</OutArgument> </Assign.To> <Assign.Value> <InArgument x:TypeArguments="x:String">[sortedString + " " + item]</InArgument> </Assign.Value> </Assign> </ActivityAction> </ForEach> <gwa1:Alert sap:VirtualizedContainerService.HintSize="287,86" Text="[sortedString]" Title="Sorted" /> </Sequence> </Activity>0 -
For a List(of String) you could use an assign activity (remember to add a reference to System.Linq):
stringList = stringList.OrderBy(Function(value) value).ToList()
And for a List(Of DataItem):
dataItemList = dataItemList.OrderBy(Function(value) value.Display).ToList()
0
Please sign in to leave a comment.
Comments
2 comments