How to concat the value of a number of fields in alphabetical order in infopath
-
Monday, April 16, 2012 9:26 AM
Hi
I need to concatentate the value of a number of fields in alphabetical order in infopath. These fields are populated from a single drop down using an add button. These fields are used to make up the dynamic name of the entry. Because these fields can be added in any order from the drop down i need to make sure they are concatenated in alphabetical order (so two entries with the same selected fields have the same string regardless of the order they were selected from the drop down.
eg 1
Field1 = a, Field2 = b, Field3= c
Field concat = a_b_c
eg 2
Field1 = c, Field2 = a, Field3 = b
Field concat = a_b_c
Any help greatly appreciated
Thks
Chris
- Edited by Whiftoff Monday, April 16, 2012 11:48 AM
All Replies
-
Wednesday, April 18, 2012 5:01 AMModerator
Hi Whiftoff,
I think there are two ways to achieve it.
- You can first sort in SharePoint list(All Items->Modify this view->Sort), then In InfoPath, use a drown list to read the list.
- You can develop With C# or javascript as the following.
C#:
XPathNavigator navigator = this.MainDataSource.CreateNavigator();
XPathNodeIterator repeatingNodes = navigator.SelectChildren("XPath of your field", "Namespace of your form");
ArrayList sortValues = new ArrayList();
foreach(XMLNode repeatingNode in repeatingNodes)
{
sortValues.Add(repeatingNode.xml);
}
sortValues.Sort();
BLOCKED SCRIPT
var thisDOM = window.external.Window.XDocument;
var repeatingNodes = thisDOM .selectNodes("XPath of your field");
var sortValues = new Array();
foreach(var repeatingNode in repeatingNodes)
{
sortValues.Add(repeatingNode.xml);
}
sortValues.Sort("SortFunctionName");
the code is from the following link, you can refer to it.
http://www.infopathdev.com/forums/t/10102.aspx
Thanks,
Jack
- Marked As Answer by Jack-GaoMicrosoft Contingent Staff, Moderator Friday, April 27, 2012 9:51 AM

