Using a Website gadget to include a custom script page in an Interactive Dashboard

2 minute read time.

Sage CRM has a wide range of different gadget types that can be included in the Interactive Dashboard.

Below you can see that I have created a custom Dashboard which includes List Gadgets, Chart Gadgets and a Record Summary Gadget. There is also a custom gadget in the top left of the dashboard.

This has been created by using a Website Gadget that references an ASP page running with in Sage CRM.

Dashboard -> Create New Web Site Gadget

In the Web Address field I added

#crm_server#/CustomPages/gadget1.asp

Note 1: #crm_server# is a special code that the Dashboard understands to refer to the current server.

Note 2: This is a static URL with no session or state information. This means that we can not directly call the main CRM ASP API which depends on the Session and State information being included in the URL.

My file gadget1.asp page contained the following code:

<%
function GetKeyValue(querystringname)
{
var strPathFull = String(Request.ServerVariables("HTTP_REFERER"));
var arrayPath = strPathFull.split("?");
var strPath = arrayPath[1];
var arrayKeys = strPath.split(" &");
for (var i=0;i
{
var arrayValue = arrayKeys[i].split("=");
if (arrayValue[0].toLowerCase()== querystringname.toLowerCase())
{
return arrayValue[1];
}
}
return "";
}
Response.Redirect("http://localhost/CRM2017/CustomPages/gadgetCustomSummary.asp?SID="+GetKeyValue("SID")+" &J=gadgetCustomSummary.asp &T=User &PopupWin=Y")
%>


Note 1: The HTTP_REFERER obtained using Request.ServerVariables("HTTP_REFERER") provides access to the originally calling URL of the Interactive Dashboard which includes Session and some state information. The SIS (Session ID) is essential for security.

Note 2: This page carries out a redirect to the target page. Response.Redirect("http://[servername]/[instancename]/CustomPages/[targetpage]asp?SID="+GetKeyValue("SID")+" &J=[targetpage].asp &T=User &PopupWin=Y")

Note 3: The &PopupWin=Y is needed otherwise it will draw all the menus in the new gadget.

gadgetCustomSummary.asp

As an example of a custom gadget this page displays the count of current 'In Progress' or 'Pending' Cases, Opportunities and Communications for the current user.

This particular gadget uses a simple HTTP meta tags to cause the page to refresh every 2 minutes.

The code can be found below.

<!-- #include file ="sagecrm.js"--><br /><%<br />//Get Context Info</p>
<p>var intRecordId = CRM.GetContextInfo("user","user_userid");<br />var oppoRecord = CRM.FindRecord("opportunity", "oppo_status='In Progress' and oppo_assigneduserid=" + intRecordId);<br />var caseRecord = CRM.FindRecord("cases", "case_status='In Progress' and case_assigneduserid=" + intRecordId);<br />var commRecord = CRM.FindRecord("Communication, vCommunicationAll", "comm_status='Pending' and cmli_comm_userid=" + intRecordId);</p>
<p>var caseContent = CRM.GetBlock("content");<br />caseContent.contents = "</p>
<p>";caseContent.contents += "";</p>
<table style="background-color: #c8006e;" width="250px">
<tbody>
<tr>
<td width="55px"></td>
<td class="TOPHEADING" style="color: white;">" + caseRecord.RecordCount+"</td>
</tr>
</tbody>
</table>
<p><br />caseContent.contents += "</p>
<p>";</p>
<table>
<tbody>
<tr>
<td> </td>
<td class="TOPCAPTION" style="color: white;">"+CRM.GetTrans("Tabnames","Cases")+"</td>
</tr>
</tbody>
</table>
<p><br />caseContent.contents += "";<br />caseContent.Width = "100px";<br />caseContent.Height = "100px";</p>
<p>var oppoContent = CRM.GetBlock("content");<br />oppoContent.contents = "</p>
<p>";oppoContent.contents += "";</p>
<table style="background-color: #64006e;" width="250px">
<tbody>
<tr>
<td width="55px"></td>
<td class="TOPHEADING" style="color: white;">" + oppoRecord.RecordCount+"</td>
</tr>
</tbody>
</table>
<p><br />oppoContent.contents += "</p>
<p>";</p>
<table>
<tbody>
<tr>
<td> </td>
<td class="TOPCAPTION" style="color: white;">"+CRM.GetTrans("Tabnames","Opportunities")+"</td>
</tr>
</tbody>
</table>
<p><br />oppoContent.contents += "";<br />oppoContent.Width = "100px";<br />oppoContent.Height = "100px";<br />oppoContent.NewLine = false;</p>
<p>var commContent = CRM.GetBlock("content");<br />commContent.contents = "</p>
<p>";commContent.contents += "";</p>
<table style="background-color: #004089;" width="250px">
<tbody>
<tr>
<td width="55px"></td>
<td class="TOPHEADING" style="color: white;">" + commRecord.RecordCount+"</td>
</tr>
</tbody>
</table>
<p><br />commContent.contents += "</p>
<p>";</p>
<table>
<tbody>
<tr>
<td> </td>
<td class="TOPCAPTION" style="color: white;">"+CRM.GetTrans("Tabnames","communications")+"</td>
</tr>
</tbody>
</table>
<p><br />commContent.contents += "";<br />commContent.Width = "100px";<br />commContent.Height = "100px";<br />commContent.NewLine = true;</p>
<p>var myBlockContainer = CRM.GetBlock("Container");<br />with (myBlockContainer)<br />{<br />AddBlock(caseContent);<br />AddBlock(oppoContent);<br />AddBlock(commContent);<br />DisplayButton(Button_Default) = false;<br />}</p>
<p>CRM.AddContent(myBlockContainer.Execute());<br />Response.Write(CRM.GetPage());</p>
<p><br />%>