3

My Environment Setup

In user profile I have a column with name as MyLocation and this is managed metadata field. My managed Metadata Term set name which i have linked to this is "Location". My managed metadata looks like below

Location (term set)
     United States (parent term)
          London (child term)
          New York
     United Kingdom
          Boston
          London

We are showing local news based on this user location.

Issue

now if user has set there location as London then we are not able to make out whether user select London with parent United Sates or United Kingdom.

Requirement

So We planned to get the ID of term which user has selected, and show the news based on the term id. But we are not able to get the ID of term in user profile. its just giving Label of term.

I am using SSOM sample code which i am using to get user details is below

public static string GetUserLocation(SPSite site, SPUser currentuser)
{

        var location = "";
        var userProfileManager = new UserProfileManager(SPServiceContext.GetContext(site));
    try
    {

        var userProfile = userProfileManager.GetUserProfile(currentuser.LoginName);

        if (userProfile != null)
        {
            var pspm = userProfileManager.DefaultProfileSubtypeProperties;

            foreach (ProfileSubtypeProperty prop in pspm.PropertiesWithSection)
            {
                if (prop.Name == "MyLocation")
                {
                    if (userProfile[prop.Name].Value != null)
                        location = userProfile[prop.Name].Value.ToString();
                }
            }

        }
    }
    catch (Exception)
    {


    }

    return location;
}

Please help me with this ASAP.

  • Can you add some code snippet / screenshot ? Are you using SSOM to get user profile and terms ? – Gautam Sheth Jan 6 '17 at 11:20
  • I am using SSOM, I have updated my question with code i am using – Raghavendra C Jan 6 '17 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.