I just got done doing something very similar, except mine were SharePoint lists. First lists was a transaction type list. Inside of this list was a lookup to an approvers list. The user selects whichever approvers should be used for each transaction type in SP.
So in Infopath the transactions list and the approvers list are both data connections. I needed to do something very similar to what you are doing. I ended up using code to create a table in my schema to store the list of all the possible approvers. I had this table filled by my Form_Load whenever the form is opened, and added a field named ApproverRequired to it as a check box.
So once the form opens we have the multi-select box showing the list of transactions. They can pick however many they want. Once they are done they click a button which calls the following code:
//This method determines which approvals are required.
//Setup Transaction Types Navigator for later use.XPathNavigator transNavRoot = DataSources["Transaction Types"].CreateNavigator();
XPathNavigator root = MainDataSource.CreateNavigator();
//This is the multi-select field XPathNodeIterator iterStandardCOSTran = root.Select("/my:COS/my:COSTransactionIdentification/my:StandardTransactions", NamespaceManager);
string selectedTransId = String.Empty;//Loop through the values in the transaction multiselectforeach (XPathNavigator transNav in iterStandardCOSTran)
{
if (!String.IsNullOrEmpty(transNav.Value))
{
selectedTransId = transNav.Value;
//This looks up the specific transaction id from the Transactions data source
XPathNavigator trans = transNavRoot.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:ID = '" + selectedTransId + "']", NamespaceManager);SetRequiredApprovers(trans.Select("d:Approval_x0020_Roles/Value", NamespaceManager));
}
}
}
So as it finds the values that were selected in the multi-select it loops through them and calls the SetRequireApprovers method which gets passed the list of approval roles that are required for that transaction type.
private void SetRequiredApprovers(XPathNodeIterator approvers)
{
//Loop through provided iterator and set each approver role it contains to required for approval.while (approvers.MoveNext())
{
//This line gets a navigator to the specific approver role we are currently looping through.
XPathNavigator approver = MainDataSource.CreateNavigator().SelectSingleNode("/my:COS/my:ApproverIdentification/my:ApprovalRole[my:ApprovalRoleID = '" + approvers.Current.Value + "']", NamespaceManager);
//Finally we set the ApprovalRequired flag to true to indicate that this approver is required.
approver.SelectSingleNode("my:ApprovalRequired", NamespaceManager).SetValue("true");
}
}
I know this is probably confusing and may be of no use to you, but I thought I would try to help, since your problem sounds similar to mine.