I am accessing the user profile property from code but it returns null value as well as false in the boolean type property.
My code is:
if (web != null)
{
SPList list = ListHelper.GetListByUrl(web.Lists,ListNames.DepartmentsUrl);
if (list != null)
{
SPQuery query = new SPQuery();
query.Query = string.Format(CamlQueries.Department.QueryForDepartmentUrl, properties.Web.Name);
SPListItemCollection coll = list.GetItems(query);
if (coll != null)
{
SPListItem item = coll[0];
var taxonomyField = item.Fields.GetFieldByInternalName(FieldNames.Department) as TaxonomyField;
var fieldValue = item[taxonomyField.Id] as TaxonomyFieldValue;
SPServiceContext contex = SPServiceContext.GetContext(properties.Web.Site);
if (contex != null)
{
UserProfileManager upm = new UserProfileManager(contex);
#region Change User Profile Properties
if (upm != null)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
UserProfile u = upm.GetUserProfile(user[0]);
if ((bool)u[FieldNames.Manager].Value)
{
properties.ErrorMessage = "Manager is already assigned to other department";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
else
{
if (groupAdded.Name.EndsWith(UserGroups.Managers.Name))
....
Here in the condition :if ((bool)u[FieldNames.Manager].Value)
I am getting false but in the user profile property from central admin it is true.
What should I do?
N.B. The property's privacy is set to Everyone.