This blog demonstrates how to create a chart from data in the current entity alongside data from related entities.
Let’s take the following scenario:
A Not For Profit Organization is using CRM 2011 to track the pledges and donations made by their donors.
Each pledge a donor makes has a Pledge Amount and will have 1 to * donations associated to it. Each Donation has a Cash-Value and a Status. The Status will have one of the following values: Outstanding, Processing, or Collected.
The CRM user that is responsible to manage the pledges for a given cause needs to be able to quickly see the status of a given pledge i.e. the original amount of the pledge and the amount collected. One possibility is to show the following chart in the Pledge form:
where:
- Pledged is the Pledge Amount. This value is only available in the Pledge entity (e.g. $1000).
- Collected is the sum of all the Cash-Value of the Donations that have been collected. (e.g. three donations @ $200 have been collected)
We will cover how to:
- Display the value of a field (Pledge Amount) from the current entity (Pledge) in the chart. This is not possible out of the box because a chart can only display field values from a related entity (Donation).
- Display the sum of the values (Cash-Value) of related entities (Donation) having a specific Status (collected).
To create this chart and display it in the Pledge form, do the following:
1. Go to Settings > Customizations > Customize the System.
2. Create a Pledge entity with the field ‘Pledge Amount’ and a Donation entity with the fields ‘Cash-Value’ and ‘Status’.
3. Open the Donation entity
4. Create a new bar chart
5. Create a series for the field Cash Value.
6. Open the Pledge main form
7. Add a One Column Section
8. Insert a Sub-Grid. Enter the unique Name and Label. Select the entity (Donations) and the default View. Also check the box ‘Show Chart Only’ in order to hide the sub-grid.
9. In the formatting tab, set the number of rows to 12
10. Save, Close, and Publish all the customizations
11. Open a Pledge form
12. You will see the following chart.
13. Add a Global OptionSet in order to be able to change the legends’ labels
- Go to Settings > Customizations > Customize the System.
- Click on ‘Option Sets’ in the left pane and click on the menu item ‘New’
- Add the 2 Options: Pledged and Collected.
14. Now we have to manually modify the chart.
15. Export the chart.
- Go to Settings > Customizations > Customize the System.
- On the left pane, select Components > Entities > Donations > Charts
- Select the chart ‘Pledge Status By Amount’
- Click on the ‘More Actions’ > Export Chart and save the chart on your hard drive
16. Open in your favorite XML editor or notepad
17. Replace the generated <fetch> with the following:
<fetch mapping="logical" aggregate="true"> <entity name="new_donation"> <link-entity name="new_pledge" to="new_pledgeid" from="new_pledgeid" link-type="outer"> <attribute alias="aggregate_pledgeamount" name="new_pledgeamount" aggregate="avg" /> </link-entity> <link-entity name="new_donation" from="new_donationid" to="new_donationid" link-type="outer"> <attribute alias="aggregate_collected" name="new_cashvalue" aggregate="sum" /> <filter> <condition attribute="statuscode" operator="eq" value="100000001" /> </filter> </link-entity> <attribute groupby="true" alias="groupby_column" name="statecode" /> </entity> </fetch> |
- The first <link-entity does an outer-join between Donation and Pledge and computes the average of all the Pledge Amounts. The problem is, to include the pledge amount attribute in the same FetchXML query that contains other aggregated attributes; we need to specify an aggregation on the pledge amount as well.
Since there will be one Pledge Amount per record, we need to compute the average in order to get the original Pledge Amount. - The second <link-entity does an outer-join between Donation and Donation. This is necessary because we want to filter the rows for a given value of the Status. The Filter clause uses the values of the Option Set that is used by Status (Collected)
18. Rename the aliases in <category> to match the ones above
<category> <measurecollection> <measure alias="aggregate_pledgeamount" /> </measurecollection> <measurecollection> <measure alias="aggregate_collected" /> </measurecollection> </category> |
19. Replace the generated <Series> with the following: Note the attribute ‘Name’ which is telling to use the Option value of the OptionsSet as labels for the legends.
<Series> <Series Name="o:new_pledgestatus,100000000" ChartType="Bar" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40, DrawingStyle=Cylinder"> <SmartLabelStyle Enabled="True" /> </Series> <Series Name="o:new_pledgestatus,100000001" ChartType="Bar" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40, DrawingStyle=Cylinder"> <SmartLabelStyle Enabled="True" /> </Series> </Series>
|
20. Add the <Legends> node manually at the end of the Chart node.
<Legends> <Legend Alignment="Center" LegendStyle="Table" Docking="right" IsEquallySpacedItems="True" Font="{0}, 11px" ShadowColor="0, 0, 0, 0" ForeColor="59, 59, 59" /> </Legends> </Chart> |
21. Remove the label ‘Active’ on the Status Axis by adding the Enabled attribute.
<AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount"> <MajorTickMark LineColor="165, 172, 181" /> <MajorGrid LineColor="Transparent" /> <LabelStyle Enabled="false" Font="{0}, 10.5px" ForeColor="59, 59, 59" /> </AxisX> |
22. Save the file and import the chart.
- Go to Settings > Customizations > Customize the System.
- On the left pane, select Components > Entities > Donations > Charts.
- Click on the ‘More Actions’ > Import Chart and browse to the modified chart on your hard drive. Click OK.
- Import will find that the chart is a duplicate. When asked, select ‘Replace’.
23. Publish all the customizations.
24. Open a Pledge entity.
Final result
Summary:
We have showed you how to manually modify CRM 2011 charts in order to:
- Display the value of a field from the current form
- Display the filtered value of the field from a related entity
- Rename the legends’ labels
For more information on how to further modify the CRM 2011 charts, see also the blogs
“CRM 2011 Charts – Know the Real Potential”, Part 1 and Part 2.
Here is the full chart XML that we modified in this example:
<visualization> <visualizationid>{AB00D3AF-49E9-E011-B89B-00155DA96A01}</visualizationid> <name>Pledge Status by Amount</name> <primaryentitytypecode>new_donation</primaryentitytypecode> <datadescription> <datadefinition> <fetchcollection> <fetch mapping="logical" aggregate="true"> <entity name="new_donation"> <link-entity name="new_pledge" to="new_pledgeid" from="new_pledgeid" link-type="outer"> <attribute alias="aggregate_pledgeamount" name="new_pledgeamount" aggregate="avg" /> </link-entity> <link-entity name="new_donation" from="new_donationid" to="new_donationid" link-type="outer"> <attribute alias="aggregate_collected" name="new_cashvalue" aggregate="sum" /> <filter> <condition attribute="statuscode" operator="eq" value="100000001" /> </filter> </link-entity> <attribute groupby="true" alias="groupby_column" name="statecode" /> </entity> </fetch> </fetchcollection> <categorycollection> <category> <measurecollection> <measure alias="aggregate_pledgeamount" /> </measurecollection> <measurecollection> <measure alias="aggregate_collected" /> </measurecollection> </category> </categorycollection> </datadefinition> </datadescription> <presentationdescription> <Chart Palette="None" PaletteCustomColors="149,189,66; 197,56,52; 55,118,193; 117,82,160; 49,171,204; 255,136,35; 168,203,104; 209,98,96; 97,142,206; 142,116,178; 93,186,215; 255,155,83"> <Series> <Series Name="o:new_pledgestatus,100000000" ChartType="Bar" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40, DrawingStyle=Cylinder"> <SmartLabelStyle Enabled="True" /> </Series> <Series Name="o:new_pledgestatus,100000001" ChartType="Bar" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40, DrawingStyle=Cylinder"> <SmartLabelStyle Enabled="True" /> </Series> </Series> <ChartAreas> <ChartArea BorderColor="White" BorderDashStyle="Solid"> <AxisY LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount"> <MajorGrid LineColor="239, 242, 246" /> <MajorTickMark LineColor="165, 172, 181" /> <LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" /> </AxisY> <AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount"> <MajorTickMark LineColor="165, 172, 181" /> <MajorGrid LineColor="Transparent" /> <LabelStyle Enabled="false" Font="{0}, 10.5px" ForeColor="59, 59, 59" /> </AxisX> </ChartArea> </ChartAreas> <Titles> <Title Alignment="TopLeft" DockingOffset="-3" Font="{0}, 13px" ForeColor="59, 59, 59"></Title> </Titles> <Legends> <Legend Alignment="Center" LegendStyle="Table" Docking="right" IsEquallySpacedItems="True" Font="{0}, 11px" ShadowColor="0, 0, 0, 0" ForeColor="59, 59, 59" /> </Legends> </Chart> </presentationdescription> <isdefault>false</isdefault> </visualization>
|