Adding a Report Button to an Existing System Screen, e.g. OpportunitiesList (for Sage CRM v7.1sp2 and earlier)

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Adding a Report Button to an Existing System Screen, e.g. OpportunitiesList (for Sage CRM v7.1sp2 and earlier)

  • Comments 12
  • Likes

Note:  This article discusses techniques relevant for Sage CRM v7.1sp2 and earlier.  If you are using Sage CRM 7.2 please refer to the articles that discuss the new Client Side API.

This article shows how to add a button to an existing system screen that will call a report.

For example if you look at the image of the OpportunitiesList screen below you can see that a button has been added that calls a popup window that displays a pdf report.

You may think that since reports are a system built behaviour it should be easy to call an individual report from a system menu like a tabgroup or from a button contained in a button group.  But unfortunately although adding a button is easy that can point to a system action there way of including the unique identifier of the individual report to run.

So how can you add a report button to call an individual report?  I will use the system action opportunitylist to demonstrate.

The steps to follow are

  1. Create Button Group linked to the OpportunitiesList system action.  Add a 'report' button to the Button group.
  2. The button's action needs to be 'customurl' and the URL should be the pseudo-URL that will call the clientside function. e.g. javascript:runReport();
  3. Define the clientside function and add it to the custom content box of the OpportunitiesList list block.

Background Information to the Code

Much of the information needed to solve this has been written about before.

Adding a button to a system screen is very easy. This is done using the Button Groups feature.  An example of how to add a custom button to a system action screen is discussed in the article "Adding a Print Button to a System Screen". 

We need to be able to call the system action responsible for calling reports.  This has been written about before in the context of ASP pages in the article "Some thoughts on Sage CRM, FOP, PDF and Reports".

The URL used to call the report has been build using several functions.  The function GetKeys() is a system built clientside function that exists by default in system screens.  This has been discussed in the article, "Grabbing Key Values client side".

The function GetKeyValue() which has been used to grab the session id has been discussed in the article, "Another Trick for Grabbing Key Values in Client Side code".

The Function that is used to pop open the window is a version of the one used in the following article: "Fine Control of PopUp windows".

Code Used in Custom Content box


<script>
function runReport()
{
var strPath = document.URL;
var arrayApp = strPath.split("/Do?");
var intReportID = 78
//intReportAction is either 1410 to display the report options or 1411 to directly run the report
//var intReportAction = 1410;
var intReportAction = 1411;
//Allowed values for strDestination are "Screen", "Adobe", "CSV", "Excel"
var strDestination = "Adobe";
var strURL = arrayApp[0] +"/Do?SID="+GetKeyValue("SID")+"&Act=";
strURL += intReportAction+GetKeys()+"&Key41="+intReportID+"&FlgNewWindow=True&Destination=";
strURL += strDestination+"&PageSize=210x297&Orientation=Landscape";
//document.write("<a href="+strURL+">test</a>");
//document.location.href=strURL; 
popUp(strURL);
}
function GetKeyValue(querystringname) 
{ 
var strPath = window.location.search.substring(1); 
var arrayKeys = strPath.split("&"); 
for (var i=0;i<arrayKeys.length;i++) 
{ 
var arrayValue = arrayKeys[i].split("="); 
if (arrayValue[0].toLowerCase()== querystringname.toLowerCase()) 
{ 
return arrayValue[1]; 
} 
} 
return ""; 
}
function popUp(URL) {
day = new Date();
id = day.getTime();
window.open(URL, id , 'toolbar=0 , scrollbars=0, location=0, statusbar=0, menubar=0 , resizable=0, width=600, height=400, left = 340, top = 200');
}
</script>

Comments
  • Jeff, nice post.  

    When I try to execute this code, the shortcut for the icon is "http://server/crm/eware.dll/runReport();" and it simply takes me to a login screen.  

    I created the button group to the opportunitieslist system action, I created the report button with a custom url named runReport(); and I added the function to the OpportunitiesList block custom content box.  Any ideas?  

    Thanks,

    Chris P.

  • Fair point!

    I've corrected the article to make clear the custom URL to be used should be:

    javascript:runReport();

  • Hi Jeff  this is exactly what I am trying to do, although I cannot find the "custom content box of the OpportunitiesList list block".  I can see it on the screen Tab but when I add it there the example you have given does not work.

  • In the Admin area

    Administration -> Customization -> Opportunity

    Find the list, OpportunityList.  Click the customise button.

    The Custom Content Box is the box marked "Custom Content".

  • Hi Jeff,

    Is there a way to also pass search criteria to the report when using this method?

  • Possibly... The Key Value 62 allows you to add the some saved search information.  e.g. &Key62=76.

  • Hi Jeff,

    Thanks. Pointed it to a saved search and it works very good.

    I however want the saved search to change depending on which record the user is currently on, luckily for me I am on a custom asp page soI can change the saved search details in SQL. Problem is even after dynamically changing the saved search in SQL it seems to be buffered in CRM somewhere so the changes are not getting to the front end, if I however go to the report using the normal navigation it picks up the changes I made in SQL.

    Any ideas?

  • Hi Jeff,

    No worries, I set the report to display rather than to automatically start running and it resolved my issue.

    It's an extra click but the ease of use is still there.

    Thanks for this.

  • Excellent!

  • Hi Jeff. This is great but how would this work in 7.2?

  • Michael

    The key bit of the code is the creation of the URL that calls the report.

    var strURL = arrayApp[0] +"/Do?SID="+GetKeyValue("SID")+"&Act=";

    strURL += intReportAction+GetKeys()+"&Key41="+intReportID+"&FlgNewWindow=True&Destination=";

    strURL += strDestination+"&PageSize=210x297&Orientation=Landscape";

    In version 7.2 onwards you can use the Client Side API to assemble the same information very easily.

    I have not rewritten this for Sage CRM 7.2 but you can see how buttons are added here: community.sagecrm.com/.../sage-crm-7-2-controlling-the-properties-of-new-buttons-adding-using-the-client-side-api.aspx

  • Hi Jeff, i've tried using Key62 to set some saved search information but this never seems to change the contents of the report. Any other ideas on passing in parameters?