I'm referencing article: http://www.markrackley.net/2014/03/17/sharepoint-20102013-tip-of-the-day/ to have a webpart for Tip of the Day.

In my case the message will ideally be Tip of the month.

Now the issue is in the Javascript code if no active message for current date set, then it will pick any old message stored in the relevant SPS list.

I'm after removing that "if" condition, but not sure how to make it for the active date should only show the active message and let the old message still be in list, but it wont pick it till the date is changed to active date.

here is the Javascript code:

<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>

<style type="text/css">



<div id="TOTD">
<span class='TOTDHeading' id="TOTDTitle"></span><br>
<span class='TOTDBody' id="TOTDTip"></span>

<script type="text/javascript">

    //if "true" is passed in, the script will look for a tip with today's date
    //if "false" is passed in, a random tip will be displayed

    function DisplayTip(useDate)
        var listName = "TOTD";
        var titleField = "Title";
        var tipField = "msg";
        var dateField = "msgdate";

        //query to retrieve msgs, NOTE if no date is used, it will return ALL msgs and select a random
        //one. If you plan to use the script in this manner, be sure that you don't put than 50 or so msgs
        //in your list
        var query = "/_api/Web/Lists/GetByTitle('"+listName+"')/items?$select="+titleField+","+tipField;
        if (useDate)
            var today = new Date();
            todayString = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
            query += "&$filter="+dateField+" eq '" + todayString + "'";
        var call = $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + query,
            type: "GET",
            dataType: "json",
            headers: {
                Accept: "application/json;odata=verbose"

   call.done(function (data,textStatus, jqXHR){
            if (data.d.results.length < 1 && useDate)
                //if not tip is found for today, just get a random tip
                //if you KNOW you will not have a tip for a specific day
                //set the initial call to pass in "false" otherwise you 
                //will notice a lag in load time.

            else {

                tipIndex = getRandomInt(0,data.d.results.length - 1);

                var title = data.d.results[tipIndex][titleField];
                var msg = data.d.results[tipIndex][tipField];



        call.fail(function (jqXHR,textStatus,errorThrown){
            alert("Error retrieving Message: " + jqXHR.responseText);


    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;


No need for external ScriptFiles and (complex) JavaScript code;

Let SharePoint do the work for you (this works in 2010,2013 & Online)

see http://viewmaster365.com/#/How

Add a Calculated Column Tip of the Day set to output a Date

Paste Formula:

="<img src='/_layouts/images/blank.gif' onload=""{"
    &"var D=GetDaysAfterToday(new Date("
    &"var H='<DIV style=font-size:medium><DIV style=font-size:x-large;color:#3982F8;>"

This outputs

You can now use all your View skills to select/filter/order tips anyway you want and create a ListViewWebPart that only displays the Tip of the day

If you do want use the extra JavaScript file then please replace odata=verbose with odata=nometadata and keep your mobile users and admins happy

  • Thanks Danny. I have already deployed the solytiin n just need the Javascript amendment. Kindly assist. – Jason Apr 27 '16 at 11:35
  • Experts any suggestions – Jason Apr 27 '16 at 23:00
  • Break your questions up in smaller problems (which you try to solve yourself) then ask questions here. Would you browse thru lines and lines of someelses code and try to understand it? – Danny '365CSI' Engelman Apr 28 '16 at 8:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.