0

Hi I am trying to get the value of SPS-WorkDays (profile property) which when you change the days you work in your MySites, it gives you an integer value. What I am trying to do with some JavaScript is to change the integer value to something more user friendly in a Script Editor web part. For example if a user chooses to only work on Thursday they would get a value ‘4’. I am using a case statement to change that to Thursday. I found some code and modified it for my purposes the only problem is that it always shows my working days no matter who’s mysites I am on. I have pasted in the code with only one case statement as there are 31 combinations. If any can help I would be grateful:

<script type=’text/javascript’>
var WorkDays = “”;

$.ajax(
{

url: _spPageContextInfo.webAbsoluteUrl + “/_api/SP.UserProfiles.PeopleManager/GetMyProperties”,
headers: { Accept: “application/json;odata=verbose” },
success: function (data) {
try {
//Get properties from user profile Json response
userDisplayName = data.d.DisplayName;
AccountName = data.d.AccountName;
var properties = data.d.UserProfileProperties.results;
for (var i = 0; i < properties.length; i++) {
var property = properties[i];

if (property.Key == “SPS-WorkDays”) {
WorkDays = property.Value;
}

}

$(‘#WorkDays’).text(WorkDays);

switch(WorkDays)
{
case “44”:
$(‘#WorkDays’).text(“Mon, Wed, Thur”);
break;
//More case statement below, to many to show
default:
document.getElementById(“ShowWorkingDays”).style.display = “none”;

}

} catch (err2) {
//alert(JSON.stringify(err2));
}
},
error: function (jQxhr, errorCode, errorThrown) {
alert(errorThrown);
}
});

</script>
<div id=”ShowWorkingDays”>:

<h2><strong>Employee working days</strong></h2>
<br />
Work Days:      <span id=”WorkDays”></span>
</div>

If I was to go on someone else’s mysite the value at the bottom would have changed but my code would still display the same values under Employee working days.

(Visited 84 times, 1 visits today)

Attachments

WorkingDays.jpg
Add a Comment