Thursday 25 October 2012

Set the @Microsoft @SharePoint Performance Point dashboard to default to yesterday's date. This will work for 2007 and 2010!

Okay, I have followed this thread for a while and tried so many methods to get this to work, eventually I hacked my way through almost all the SP2010 and SP2007 JavaScript and found the following to work on SP2010 and I had it working in SP2007 with a different tad prefix.

1.       find out what the Javascript id prefix of your calendar parts are.

                                 i.            -To do this, start your dashboard in IE8 or IE9 and hit F12 to start the Javascript Debugger.

                               ii.            -User the Javascript GetElementByTagName("TD") to get a full list of all the TD tags on the page.

                              iii.            -Look for the tags that have a GUID in the id and that end with _Selection and Selection_Toggle.

                             iv.            -These will be your calendar filter parts. Note the starting prefix (in SP2007 it was ct_100_ in SP2010 it is pps_)

2.       add the following Javascript to the end of your master page which is used for the Dashboards (look at end of the post)

3.       save the master page and refresh your browser and the date should change to yesterday. I have also created this for a dashboard with two calendar filters on it to allow for date range filtering and this will set the first date to 11 days earlier and the second date to yesterday.

                <script type="text/JavaScript">

                var isFirstLoad;

                var calendarLoaded = false;

                var srcID = "ctl00_m_WebPart_293af46d1c5c4320893d47f86614325bSelection";

                var strDate = "Tue Aug 2 00:00:00 UTC+0200 2011";

                var t;

                var dateBackA = 1;

                var dateBackB = 10;

                testForCalendar();

                function testForCalendar()

                {

                                isFirstLoad = true;

                                if(calendarLoaded != true)

                                                t = setTimeout("waitForIt()", 5);

                }

                function waitForIt()

                {

                                var foundControl = -1;

                                var t = document.getElementsByTagName("TD");

                                var ts = "";

                                var subDateFound = false;

                                var xPoint = 0;

                                for(var x = 0; x < t.length; x++)

                                {

                                                if((t[x].id.indexOf("pps_") == 0) && t[x].id.indexOf("Selection_Toggle") > 0)

                                                {

                                                                foundControl = x;

                                                                ts = t[x].id.substring(0, t[x].id.indexOf("_Toggle"));

                                                                xPoint = x;

                                                                x = t.length;

                                                }

                                }

                                if(foundControl > -1)

                                {

                                                if(isFirstLoad == true)

                                                {             

                                                                if(t[xPoint].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML.indexOf("Start Date:") > -1)

                                                                                calendarIntercept(ts, calendarDate(new Date(), dateBackB));

                                                                else

                                                                                calendarIntercept(ts, calendarDate(new Date(), dateBackA));

                                                                waitForItSub(xPoint, ts);

                                                                calendarLoaded = true;

                                                                isFirstLoad = false;

                                                }

                                                else

                                                                t = setTimeout("waitForIt()", 5);

                                }

                                else

                                                t = setTimeout("waitForIt()", 5);              

                }

                function waitForItSub(startPoint, firstTag)

                {

                                var foundControl = -1;

                                var t = document.getElementsByTagName("TD");

                                var tsub = "";

                                var xPointNew = 0;

                                for(var x = (startPoint++); x < t.length; x++)

                                {

                                                if(t[x].id.indexOf(firstTag) == -1)

                                                {

                                                                if((t[x].id.indexOf("pps_") == 0) && t[x].id.indexOf("Selection_Toggle") > 0)

                                                                {

                                                                                foundControl = x;

                                                                                tsub = t[x].id.substring(0, t[x].id.indexOf("_Toggle"));

                                                                                xPointNew = x;

                                                                                x = t.length;

                                                                }

                                                }

                                }

                                if(foundControl > -1)

                                {

                                                if(isFirstLoad == true)

                                                {             

                                                                if(t[xPointNew].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML.indexOf("Start Date:") > -1)

                                                                                calendarIntercept(tsub, calendarDate(new Date(), dateBackB));

                                                                else

                                                                                calendarIntercept(tsub, calendarDate(new Date(), dateBackA));

                                                                calendarLoaded = true;

                                                                isFirstLoad = false;

                                                }

                                }

                }

                function calendarIntercept(inSrcID, inDate)

                {

                                strDate = (inDate.getMonth()+1) + "/" + inDate.getDate() + "/" + inDate.getFullYear();

                                pps_TI_calendar_render ( inSrcID, strDate , strDate );

                }

                function calendarDate(inDate, daysBack)

                {

                                var returnValue = new Date();

                                returnValue.setDate(returnValue.getDate() - daysBack);

                                return returnValue;

                }

                </script>

Posted via email from Emil Swanepoel

No comments: