Tuesday 6 December 2016

Read Custom User Property created in Central Admin using JavaScript

Hi All,

I have faced recently one problem. Created a custom user property in Central Admin and reading property using JSOM as below.
/**** Code Start****/
$(document).ready(function(){
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', CallClientOM);
});
function CallClientOM()
{
var context = new SP.ClientContext.get_current();
this.website = context.get_web();
this.currentUser = website.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args)
{  
  get_user_profile_by_login(currentUser.get_loginName());
}

function get_user_profile_by_login(login) {
$().SPServices({
 operation: "GetUserProfileByName",
 async: false,
 AccountName: login,
 completefunc: function (xData, Status) {
Supervisor = getUPValue(xData.responseXML, "Supervisor");
$("input[title='Supervisor']").val(Supervisor);
  }
});
}
function getUPValue(x, p) {
  var thisValue = $(x).SPFilterNode("PropertyData").filter(function() {
    return $(this).find("Name").text() == p;
  }).find("Values").text();
  return thisValue;
}
/**** Code End****/

Problem: Here I have created Supervisor field as custom user property, but I am not able to read
from the code(as a non admin). I was set as, Policy Settings -> Default Privacy Setting -> Only Me.
Solution: While creating the property set as below:
Policy Settings -> Default Privacy Setting -> Everyone.
Then it worked!!!



SharePoint Timer Job Run Mechanisms

If you want to run it every TEN MINUTES,use SPMinuteSchedule class to configure:
SPMinuteSchedule minSchedule = new SPMinuteSchedule();
minSchedule.BeginSecond = 0;
minSchedule.EndSecond = 5;
minSchedule.Interval = 10;
tempJob.Schedule = minSchedule;
tempJob.Update();


If you want to run it at 11:05 PM every day, use SPDailySchedule class to configure:
SPDailySchedule tempSchedule = new SPDailySchedule();
tempSchedule.BeginHour = 23;
tempSchedule.BeginMinute=5;
tempSchedule.BeginSecond = 0;
tempSchedule.EndSecond = 15;
tempSchedule.EndMinute = 5;
tempSchedule.EndHour = 23;
tempJob.Schedule = schedule;
tempJob.Update();


If you want to run it on the 1st of every month between 1:15am to 1:30am, use SPMonthlySchedule
SPMonthlySchedule schedule = new SPMonthlySchedule();
schedule.BeginDay = 1;
schedule.EndDay = 1;
schedule.BeginHour = 1;
schedule.EndHour = 1;
schedule.BeginMinute = 15;
schedule.EndMinute = 30;
tempJob.Schedule = schedule;
tempJob.Update();

If you want to run on Monday every week between 2:01:00 am to 2:01:05 am, use SPWeeklySchedule
SPWeeklySchedule schedule = new SPWeeklySchedule();
schedule.BeginDayOfWeek = DayOfWeek.Monday;
schedule.BeginHour = 2;
schedule.BeginMinute = 1;
schedule.BeginSecond = 0;
schedule.EndSecond = 5;
schedule.EndMinute = 1;
schedule.EndHour = 2;
schedule.EndDayOfWeek = DayOfWeek.Monday;
tempJob.Schedule = schedule;
tempJob.Update();


If you want to run it every year on Jan 23 at 9:05AM, use SPYearlySchedule
SPYearlySchedule JobSchedule = new SPYearlySchedule();
JobSchedule.BeginMonth = 1;
JobSchedule.EndMonth = 1;
JobSchedule.BeginDay = 23;
JobSchedule.EndDay = 23;
JobSchedule.BeginHour = 9;
JobSchedule.EndHour = 9;
JobSchedule.BeginMinute = 5;
JobSchedule.EndMinute = 5;
JobSchedule.BeginSecond = 0;
JobSchedule.EndSecond = 5;
tempJob.Schedule = schedule;
tempJob.Update();

Owstimer.exe is the worker process to debug the code.