4

I am merely trying to use the GetUserProfileByName service to get some details on a user from the AD. For this I opted to use javascript. After a little bit of research, and a significant amount of tinkering, I managed to connect to the webservice and successfully retrieve the data.

I used a simple if statement to compare the 'name' of the property in order to get the specific value I want.

if(xmlDoc.getElementsByTagName("Name")[i].childNodes[0].nodeValue == "Department")
{
    property = xmlDoc.getElementsByTagName("Value")[i].childNodes[0].nodeValue;
}

At this point I started noticing some discrepancies. I seemed to not be getting the property I specify in the comparison. For example if I specify "Department" it returns the email. After a lot of struggling i finally decided to just drop all the "Name" and "Value" fields into two arrays without any comparison and display them next to each other.

for(i = 0; i < 13 ; i++)
{
    description[i] = xmlDoc.getElementsByTagName("Name")[i].childNodes[0].nodeValue;
    elements[i] = xmlDoc.getElementsByTagName("Value")[i].childNodes[0].nodeValue;
}

The conclusion I got from this was that the two fields clearly did not match up with each other:

UserProfile_GUID: 65f017dc-b892-4afa-8730-5e8f73aa7b86
AccountName: CAPETOWN\ANEL5
FirstName: Abraham
SPS-PhoneticFirstName: Nel
LastName: Abraham Nel
SPS-PhoneticLastName: 021 ### ####
PreferredName: CRS - Info Sys & Tech
SPS-PhoneticDisplayName: Contractor
WorkPhone: Contractor
Department: ANEL5
Title: CN=Abraham Nel,OU=Standard,OU=Users,OU=End-User Services,DC=###,DC=###,DC=###
SPS-JobTitle: ###@###.###
Manager: Cape Town Civic Centre Podium Block

Any idea why this would be happening?

Result from trying to parse the entire XML document to string:

falsefalseUserProfile_GUIDNotSetb21ec99c-2ad9-40a8-9d45-a3273c92ee5afalsefalseAccountNameNotSetCAPETOWN\AHEYNESfalsefalseFirstNameNotSetAshleyfalsefalseSPS-PhoneticFirstNameNotSetfalsefalseLastNameNotSetHeynesfalsefalseSPS-PhoneticLastNameNotSetfalsefalsePreferredNameNotSetAshley HeynesfalsefalseSPS-PhoneticDisplayNameNotSetfalsefalseWorkPhoneNotSet021 400 ####falsefalseDepartmentNotSetCRS - Info Sys & TechfalsefalseTitleNotSetAssistant Professional OfficerfalsefalseSPS-JobTitleNotSetAssistant Professional OfficerfalsefalseManagerNotSetCAPETOWN\DSISSINGfalsefalseAboutMeNotSetfalsefalsePersonalSpaceNotSetfalsefalsePictureURLNotSetfalsefalseUserNameNotSetAHEYNESfalsefalseQuickLinksNotSetfalsefalseWebSiteNotSetfalsefalsePublicSiteRedirectNotSetfalsefalseSPS-Dotted-lineNotSetfalsefalseSPS-PeersNotSetfalsefalseSPS-ResponsibilityNotSetfalsefalseSPS-SipAddressNotSetfalsefalseSPS-MySiteUpgradeNotSetfalsefalseSPS-ProxyAddressesNotSetfalsefalseSPS-HireDateNotSetfalsefalseSPS-DisplayOrderNotSetfalsefalseSPS-ClaimIDNotSetfalsefalseSPS-ClaimProviderIDNotSetfalsefalseSPS-ClaimProviderTypeNotSetfalsefalseSPS-SavedAccountNameNotSetfalsefalseSPS-ResourceAccountNameNotSetfalsefalseSPS-ObjectExistsNotSetfalsefalseSPS-MasterAccountNameNotSetfalsefalseSPS-DistinguishedNameNotSetCN=Ashley Heynes,OU=Developers,OU=Users,OU=End-User Services,DC=##,DC=##,DC=##falsefalseSPS-SourceObjectDNNotSetfalsefalseWorkEmailNotSet##.##@##.##.##falsefalseCellPhoneNotSetfalsefalseFaxNotSetfalsefalseOfficeNotSetCape Town Paul Sauer BuildingfalsefalseSPS-LocationNotSetfalsefalseSPS-TimeZoneNotSetfalsefalseAssistantNotSetfalsefalseSPS-PastProjectsNotSetfalsefalseSPS-SkillsNotSetfalsefalseSPS-SchoolNotSetfalsefalseSPS-BirthdayNotSetfalsefalseSPS-StatusNotesNotSetfalsefalseSPS-InterestsNotSetfalsefalseSPS-EmailOptinNotSet

Carel
  • 2,063
  • 8
  • 39
  • 65
  • What does the returned XML document look like? Do names and values line up properly in the XML itself? One possibility is that the getElementsByTagName() function is not returning tags in the order in which they appear in the document. Another possibility might be the presence of more or less Value elements than Name elements, so they get out of sync when looked up only by index. We'd need to see the XML to be sure. – John Nov 24 '12 at 05:15
  • @John : I apologize, but I am rather new to SharePoint and making use of web services and such. What I did was call the web service on a page with JavaScript and write it to a blank web page on a SharePoint site. Does this create a XML and store it somewhere on the site? Can I specify the web service to return the XML document? What is suspected when I worked on this was that there are more Name elements that Value elements, but thought that they would be indexed specifically with Name element to Value element. In this I was apparently wrong. – Carel Nov 26 '12 at 06:14
  • @John : I checked my code again and saw that I actually do get an XML variable back from the web service. I did some Google-ing tried to write the entire xml to the screen using _var string = xmlNode.xml;_ This seemed to return a lot of Value elements and nothing in any kind of XML format. I appended it to the question above regardless. – Carel Nov 26 '12 at 08:00

1 Answers1

1

Searched around and it seems that the XML structure doesn't lend itself to the logic you're using. The XML looks like this:

PropertyData*
    Name
    Values
        ValueData
            Value

I'm not sure about the cardinality of each, but I reckon it's safer to iterate over xmlDoc.getElementsByTagName('PropertyData') and then find the Name and (perhaps multiple) Value elements within that block.

var properties = xmlDoc.getElementsByTagName("PropertyData");

for (var i = 0, item; item = properties[i]; ++i) {
    // search for Name and Value inside here
}

Update

It most likely is caused by multiple values for FirstName: Abraham, Nel and Abraham Nel.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
  • The above method seems intriguing. The _getElementsByTagName("PropertyData");_ seems to return an array of xml variables. I am currently trying to figure how to find the values inside each of these xml elements: `falsefalseFirstNamePublicAbraham` – Carel Nov 26 '12 at 09:10
  • @Carel In the loop I've created, each `item` is another XML node that you can perform searches on. – Ja͢ck Nov 26 '12 at 09:25
  • Ok, so I search using _item.getElementsByTagName("Name")[0].childNodes[0].nodeValue_ etc, but as soon as I attempt to search on a **value** that is affiliated with a name starting with SPS eg: SPS-PhoneticFirstName the loop fails. If I manually search the value around these values with a hardcoded if statement: `if(i == 8)`, I actually get accurate results. Its pretty hard dong this in IE with no debugging tools. – Carel Nov 26 '12 at 10:09
  • Ahh. I upgraded my IE and used the F12 developer tools and determined that i need something like this: `if(item.getElementsByTagName("Value")[0] != null)`, as the value for some of the fields are null. – Carel Nov 26 '12 at 10:14
  • @Carel That does sound reasonable; a `Value` doesn't always have to exist, in which case the `item` only has a name but no value. – Ja͢ck Nov 26 '12 at 10:19