none
object reference error on contact selector when you resolve a name then delete it RRS feed

  • Question

  • I have several contact selectors on a form I am making.  They are requestor, manager, HR Rep.

    I have code in my workflow that reads the login name from the contact selectors. 

    What I have found is that if the fields are blank my code works fine, if they have values in them they work fine also; however if I resolve a name in a field, then delete it, and then try to read the value from the blank field my code will throw an object reference error.  This should not happen because I am checking for null references or should be at least.

    Any idea on whats going on?

    Code to get values
    Dim iFile As SPFile = workflowProperties.Item.File
    Dim xmlFormData As Byte() = iFile.OpenBinary
    Dim iForm As XPathDocument
    Using ms As New MemoryStream(xmlFormData)
         iForm = New XPathDocument(ms)
         ms.Close()
    End Using
    Dim xNav As XPathNavigator = iForm.CreateNavigator
    Dim nm As New XmlNamespaceManager(New NameTable())
    nm.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-09T18:46:49")
    
    If Not xNav.SelectSingleNode("/my:myFields/my:requestor/my:Person/my:AccountId", nm).Value Is Nothing Then
           requestor = xNav.SelectSingleNode("/my:myFields/my:requestor/my:Person/my:AccountId", nm).Value.ToString
    End If
    If Not xNav.SelectSingleNode("/my:myFields/my:manager/my:Person/my:AccountId", nm).Value Is Nothing Then
           manager = xNav.SelectSingleNode("/my:myFields/my:manager/my:Person/my:AccountId", nm).Value.ToString
    End If
    If Not xNav.SelectSingleNode("/my:myFields/my:hr/my:Person/my:AccountId", nm).Value Is Nothing Then
         hr = xNav.SelectSingleNode("/my:myFields/my:hr/my:Person/my:AccountId", nm).Value.ToString
    End If


    Friday, June 26, 2009 5:34 PM

Answers

  • Hi,

    In your code, you are directly using ‘.Value’ property. You are deleting the node and asking for value in that node. At that time ‘.Value’ property gives you a run time error about object reference as the node is not there actually.

    Try to see the node in debug after you have deleted, then you can understand clearly.

     


    Thanks, Rajitha.
    • Edited by RajithaS Monday, June 29, 2009 6:06 AM
    • Marked as answer by GreenWaterBoy Monday, June 29, 2009 6:14 PM
    Monday, June 29, 2009 6:04 AM

All replies

  • I can't help with the code, but I can tell you that you don't need code to get the login name from the info in the contact selector.
    SharePoint Architect || My Blog
    Friday, June 26, 2009 6:23 PM
  • Edit - Nevermind, I just looked at your blog and I see what your talking about.  Personally since I have to write a workflow in VS anyways the coding method seems easier for what Im doing.

    Friday, June 26, 2009 7:46 PM
  • The contact selector has 3 nods, one of which is AccountID.  When a name is resolved in the Contact Selector, this node is populated with the full domain name (i.e. domain\username).  As you can see, this only requires a simple substring-after(AccountID,"\") to strip out the username that can then be used for many things without code.  The username is the login name, right?  I don't know what you're doing with the login name after that, but my blog post shows some nifty uses without code:

    InfoPath - Get user information without writing code (extended)

    The point of this link is that the username (second half of what you get from AccountID) is the exact parameter expected by the built-in UserProfileService that MOSS exposes (if you use MOSS), and it goes by the name of AccountName.  You send the username/login to this field and run the query to return the entire set of profile info.
    SharePoint Architect || My Blog
    Friday, June 26, 2009 7:56 PM
  • Hi,

    In your code, you are directly using ‘.Value’ property. You are deleting the node and asking for value in that node. At that time ‘.Value’ property gives you a run time error about object reference as the node is not there actually.

    Try to see the node in debug after you have deleted, then you can understand clearly.

     


    Thanks, Rajitha.
    • Edited by RajithaS Monday, June 29, 2009 6:06 AM
    • Marked as answer by GreenWaterBoy Monday, June 29, 2009 6:14 PM
    Monday, June 29, 2009 6:04 AM
  • Removing the .Value fixed it thanks!

    Monday, June 29, 2009 6:14 PM