Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I may be missing something. I have a Multiple Selection List box in a Section. See attached pic. When I right click on the grpApplications and copy XPath it gives me /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications when I right click for XPath on the fldApplicatins it gives me /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications

In the code (code posted below) I am referencing the /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications and I get no value. but I used /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications I get a value for selected item in the listbox.

But I am still getting error NullReferenceException "object reference not set to an instance of an object" on string appName line. The AppID looks like this "\n\t\t\t262265264143\n\t\t" instead of whole number in debug. but when I click on the binocular is shows 262265264143 but with spaces/lines before and after this.enter image description here

XPathNavigator MainDS = MainDataSource.CreateNavigator();
XPathNodeIterator iterApp = MainDS.Select("/my:myFields/my:grpAccessOfficeEquipment/my:grpApplications", NamespaceManager);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (iterApp.MoveNext())
{
    string AppID = iterApp.Current.Value;
    //int lookupID = Convert.ToInt16(value);
    XPathNavigator secAPPDS = DataSources["SupportEscalationList"].CreateNavigator();
    string appName = secAPPDS.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[@ID = '" + AppID + "']/@ApplicationProcess", NamespaceManager).Value;
    sb.Append(appName);
    item["ApplicationProcess"] = sb.ToString(); // because applicationprocess column in target sp list is single text type column
}
share|improve this question
    
Is the Multiple Selection List box available for Browser? I read an article (bizsupportonline.net/blog/2009/07/…) saying this control is only available to Infopath local client. Any help will be appreciated. It's been more than half a day and i really want to resolve this today. –  M. Todd Sep 14 '12 at 18:25
    
In 2010 it is available (it is not available in Infopath 2007 browser forms what that article is about). Could you share your IP template with VSTA project? –  Gennady Vanin Novosibirsk Sep 14 '12 at 19:46
    
sure. do u have an email? –  M. Todd Sep 14 '12 at 19:58
    
Got it. Loking in. Removed my prev comment with Email –  Gennady Vanin Novosibirsk Sep 15 '12 at 5:50
add comment

1 Answer 1

up vote 0 down vote accepted

First, change

while (iterApp.MoveNext())

to

iterApp.MoveNext();
while (iterApp.MoveNext())

because at the beginning iterApp is positioned before the first item, i.e. at no item at all.

Then, if you change Value: in Multiple-Selection List Box Properties (Data tab) from ID to d:ApplicationProcess of field fldApplications, i.e. from your current

Your Current Multiple-Selection List Box Properties
Fig.1. Your Current Multiple-Selection List Box Properties

to

Multiple-Selection List Box Properties after "Value:" change Fig.2. Multiple-Selection List Box Properties after "Value:" changed

and change the code to

//with Multiple-Selection List Box Properties of fldApplications according to Fig.2. 

XPathNavigator MainDS = MainDataSource.CreateNavigator();  
XPathNodeIterator iterApp =  
    MainDS.Select    
     ("/my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications",    
          NamespaceManager);   

System.Text.StringBuilder sb = new System.Text.StringBuilder();

iterApp.MoveNext();
while (iterApp.MoveNext())
{
    string AppName = iterApp.Current.Value;

    sb.Append(appName);  
    sb.Append(";");//this should be useful for debugging
    //the next line is out of question, so I commented it out  
    //item["ApplicationProcess"] = sb.ToString(); 
}

//this inserted to check the code  
MainDS.SelectSingleNode("/my:myFields/my:TxtBox",
          NamespaceManager).SetValue(sb.ToString());

then it should work without errors.

If you still want to make it differently or it does not work, please send me your SupportEscalationList, for example as STP file (better with included conet)

Update:

So, I understood that this buggy code came from

I tested it in Infopath 2010 + Sharepoint 2010 Online (Office 365)

If to return to perverted overcomplicated way of doing it, then code should run with following code (afteк removing all errors with quotes, etc.)

//with Multiple-Selection List Box Properties of fldApplications according to Fig.1. 

XPathNavigator MainDS = MainDataSource.CreateNavigator();  
XPathNodeIterator iterApp =  
    MainDS.Select  
        ("/my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications",    
         NamespaceManager); 

System.Text.StringBuilder sb = new System.Text.StringBuilder();

iterApp.MoveNext();
while (iterApp.MoveNext())
{
    string AppID = iterApp.Current.Value;

    XPathNavigator secAPPDS =   
            DataSources["SupportEscalationList"].CreateNavigator();
    string appName =  
         secAPPDS.SelectSingleNode
            ("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:ID =" 
            + AppID + 
            "]/d:ApplicationProcess", NamespaceManager).Value;

    sb.Append(appName);  
    sb.Append(";");//this should be useful for debugging
    //the next line is out of question, so I commented it out  
    //item["ApplicationProcess"] = sb.ToString();   
}

//inserted this to check that code works    
MainDS.SelectSingleNode("/my:myFields/my:TxtBox",
          NamespaceManager).SetValue(sb.ToString());  
share|improve this answer
    
Vanin - Thank you so much for helping me out on this. I spent 2 days on this issue before posting it here. I really appreciate it your full support and time on this. Thanks a MILLION. –  M. Todd Sep 17 '12 at 12:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.