KPI Fix for SharePoint 2013

Wrote a fix for KPIs loading on SharePoint 2013:



1) Create a file called KPIFix.js and save it to a document library on your SharePoint site.

// Fix for KPI loading
var arrayKPIPanelIds = [];
var KPIPanelIndex = 0;
function kpiEndRequestHandler()
{
    try{
        if (KPIPanelIndex < arrayKPIPanelIds.length)
        {
            var pid=arrayKPIPanelIds[KPIPanelIndex];
            __doPostBack(pid,"");
            KPIPanelIndex++;
            Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(kpiEndRequestHandler);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(kpiEndRequestHandler);
        }
    }
    catch (e)
    {
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(kpiEndRequestHandler);
    }
}
function updateStatusLists()
{
    $("div[id*='__upPanel']").each(
        function (index)
        {
            var udpId = this.id;
            var pbId = udpId.replace("__upPanel", "$KpiPostBackEventHandler");
            var btnID = udpId.replace("__upPanel", "_button");
            arrayKPIPanelIds.push(udpId);
            $(this).append("<button id='" + btnID + "' onclick='__doPostBack(&quot;" + udpId + "&quot;,&quot;&quot;);'>Load KPIs</button>");
        }
        );
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(kpiEndRequestHandler);
    //attempt a postback to start
    if (arrayKPIPanelIds.length > 0)
    {
        __doPostBack(arrayKPIPanelIds[0], "");
    }
}
$(document).ready(
    function () {
        var kpiimages = $("div[id*='kpiimagediv'] img");
        if (kpiimages.length > 0)
        {
            if (kpiimages[0].src.toLowerCase().indexOf("/_layouts/15/images/kpiprogressbar.gif") >=0)
            {
                updateStatusLists();
            }
        }
    }
    );
2) Add a Script Editor Web Part with a reference to the JavaScript file.

NOTE: This script uses jQuery, so you'll need a copy of jQuery and a reference to the jQuery library on your page.  You can get a copy of jQuery here:  http://jquery.com


 For example, if you have a document library called Scripts where you placed your scripts:

 <script language="JavaScript" src="/Scripts/jquery-1.11.3.min.js"></script>
<script language="JavaScript" src="/Scripts/KPIFix.js"></script>


3) KPIs will now load on the page.


References:
https://social.technet.microsoft.com/Forums/ie/en-US/8b39e238-46e8-4ab8-9fcb-902df2b6bd1d/multiple-kpi-web-parts-in-one-page-endless-loading-time?forum=sharepointadminprevious&prof=required



Comments

Popular posts from this blog

How To use ASPNET_SetReg to store encrypted data in the registry and then decrypt the data for use in your app

Nostalgia for SNL's Il Returno De Hercules

PowerShell Script to Clean the Windows Installer Directory