Add greeting to your classic SharePoint site


This will add in a customized greeting to your user, and change to morning, afternoon, or night based on the time of day.

1) Add this script into your Master Page

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
var currentUser;
function init(){
    this.clientContext = new SP.ClientContext.get_current();
    this.oWeb = clientContext.get_web();
    currentUser = this.oWeb.get_currentUser();
    this.clientContext.load(currentUser);
    this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
}

function onQuerySucceeded() {

    document.getElementById('userTitle').innerHTML = currentUser.get_title();
    document.getElementById('userEmail').innerHTML = currentUser.get_email();
}

function onQueryFailed(sender, args) {
    alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>


<div id="OutlookBox">
<h1>
<script type="text/javascript">
var myDate = new Date();
var strout;
strout='<a href="https://www.yammer.com">';
/* hour is before noon */
if ( myDate.getHours() < 12 )
{
    strout += 'Good Morning <span id="userTitle"></span></a>';
}
else  /* Hour is from noon to 5pm (actually to 5:59 pm) */
if ( myDate.getHours() >= 12 && myDate.getHours() <= 17 )
{
    strout += "Good Afternoon <span id='userTitle'></span></a>";
}
else  /* the hour is after 5pm, so it is between 6pm and midnight */
if ( myDate.getHours() > 17 && myDate.getHours() <= 24 )
{
    strout += "Good Evening <span id='userTitle'></span></a>";
}
else  /* the hour is not between 0 and 24, so something is wrong */
{
    strout += "I'm not sure what time it is ";
}
 document.write(strout);
</script>
<div>
    <span id="userTitle"></span>
</div>


</h1>
</div>

2) Add Style with CSS
You can change this up based on your page layout, but here is an example of what I used:

#OutlookBox{
display:visible;
position:absolute;
top:17px;
left:207px;
font-size:large;
}



Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment