Using the Profitability Reporting Widget with Custom Objects
Accounting provides the components you need to embed a widget on the Account and Product detail page to view a tabular report of the current record's profitability. This is explained in Using the Profitability Reporting Widget.
You can embed the widget onto another object's detail page but doing so involves creating a Visualforce Page specific to your chosen object. The easiest way to do this is by copying the markup from the Visualforce Page provided for the Account or Product object, and pasting it into a new Visualforce Page for your chosen object. Ensure that you are logged in as System Administrator then:
- From Setup, click Develop | Pages.
- Click on AccountProfitabilityReport or ProductProfitabilityReport in the list of Visualforce Pages.
- Copy the content on the Visualforce Markup tab and paste it to a temporary text file, e.g. in Notepad.
- Go back to the list of Visualforce Pages and click New to create a new page.
- Enter a label, name and description.
- Replace the content on the Visualforce Markup tab with the content you copied at step 3.
- Replace the object name with the API name of your chosen object. The markup for the AccountProfitabilityReport Visualforce Page is shown below with the object API name underlined and shaded green; you must replace all three occurrences with the API name of your chosen object.
<apex:page standardController="Account" showHeader="true" sidebar="true" standardStylesheets="true">
<!-- Hidden field so we can get the account name from the standard controller -->
<span style="display:none;">{!account.name}</span>
<c2g:ProfitabilityReportingWidget record="{!account}" filter-fieldname="{!$ObjectType.c2g__codaTransactionLineItem__c.name}.{!$ObjectType.c2g__codaTransactionLineItem__c.fields.c2g__Account__c.name}" />
</apex:page>
- Next replace the fieldname with the full API name of a filterable field in the report. This will filter the report results by the specified field (matched to the record being viewed). This must be a lookup field, and the object it points at must be your chosen object. The markup for the AccountProfitabilityReport Visualforce Page is shown below with the filterable field API name underlined and shaded green.
<apex:page standardController="Account" showHeader="true" sidebar="true" standardStylesheets="true">
<!-- Hidden field so we can get the account name from the standard controller -->
<span style="display:none;">{!account.name}</span><c2g:ProfitabilityReportingWidget record="{!account}" filter-fieldname="{!$ObjectType.c2g__codaTransactionLineItem__c.name}.{!$ObjectType.c2g__codaTransactionLineItem__c.fields.c2g__Account__c.name}" />
</apex:page>
- Save your Visualforce Page, then add it to the page layout of your chosen object. For best display results add it to a new single-column section in the page layout.