savedquery
newSavedQuery = new savedquery();
newSavedQuery.name =
"Sales Pipeline Funnel";
newSavedQuery.fetchxml
= @"
<fetch version='1.0'
output-format='xml-platform'
mapping='logical'
distinct='false'>
<entity name='opportunity'>
<attribute
name='name'/>
<attribute
name='customerid'/>
<attribute
name='estimatedvalue'/>
<attribute
name='statuscode'/>
<attribute
name='opportunityid'/>
<order
attribute='name' descending='false'/>
</entity>
</fetch>
";
newSavedQuery.returnedtypecode
= EntityName.opportunity.ToString();
newSavedQuery.layoutxml
= @"<grid name='resultset' object='3' jump='name'
select='1' icon='1'
preview='1'>
<row
name='result' id='opportunityid'>
<cell
name='name' width='300' />
<cell
name='customerid' width='150' />
<cell
name='estimatedvalue' width='100' />
<cell
name='statuscode' width='100' />
</row>
</grid>";
newSavedQuery.querytype
= new CrmNumber();
newSavedQuery.querytype.Value
= SavedQueryType.MainApplicationView;
Guid viewId =
service.Create(newSavedQuery);
2. Presentation: Then you
need to write the following Presentation for that.
string presentationXml = @"
<Chart Palette='BrightPastel'>
<Series>
<Series _Template_='All' ShadowOffset='2'
BorderColor='64, 64, 64' BorderDashStyle='Solid'
BorderWidth='1' IsValueShownAsLabel='true'
Font='Tahoma, 6.75pt, GdiCharSet=0'
LabelForeColor='100, 100, 100'
CustomProperties='FunnelLabelStyle=Outside'
ChartType='Funnel'>
<SmartLabelStyle Enabled='True' />
<Points />
</Series>
</Series>
<ChartAreas>
<ChartArea _Template_='All' BackColor='Transparent'
BorderColor='Transparent' BorderDashStyle='Solid'>
<Area3DStyle Enable3D='True' IsClustered='True' />
</ChartArea>
</ChartAreas>
<Legends>
<Legend _Template_='All' Alignment='Center'
LegendStyle='Table' Docking='Bottom'
IsEquallySpacedItems='True' BackColor='White'
BorderColor='228, 228, 228' BorderWidth='0'
Font='Tahoma, 8pt, GdiCharSet=0'
ShadowColor='0, 0, 0, 0' ForeColor='100, 100, 100'>
</Legend>
</Legends>
<Titles>
<Title _Template_='All'
Font='Tahoma, 9pt, style=Bold, GdiCharSet=0'
ForeColor='102, 102, 102'>
</Title>
</Titles>
<BorderSkin PageColor='Control'
BackColor='CornflowerBlue'
BackSecondaryColor='CornflowerBlue' />
</Chart>";
3.
Data Xml:
Below we have created the Data XML for that. In the Data XML we need to provide
the Presentation and the Fetch XML view Id, as given below.
// Set the data XML string.
string dataXml = @"
<datadefinition>
<fetchcollection>
<fetch mapping='logical'
count='10'
aggregate='true'>
<entity name='opportunity'>
<attribute name='estimatedvalue_base'
aggregate='sum'
alias='sum_estimatedvalue_base'/>
<attribute name='stepname' groupby='true' alias='stepname'/>
<order alias='stepname' descending='false' />
</entity>
</fetch>
</fetchcollection>
<categorycollection>
<category>
<measurecollection>
<measure alias='sum_estimatedvalue_base'/>
</measurecollection>
</category>
</categorycollection>
</datadefinition>";
// Create the visualization entity instance.
savedqueryvisualization newSavedQueryVisualization = new savedqueryvisualization();
newSavedQueryVisualization.name = "Example Visualization";
newSavedQueryVisualization.presentationdescription = presentationXml;
newSavedQueryVisualization.datadescription = dataXml;
newSavedQueryVisualization.savedqueryid = new Lookup();
newSavedQueryVisualization.savedqueryid.Value = viewId;
Guid newSavedQueryVisualizationId = service.Create(newSavedQueryVisualization);
After doing the above things please call the
Publish request, As given below.
//Publish the Opportunity entity customizations.
PublishXmlRequest request = new PublishXmlRequest();
request.ParameterXml = @"
<importexportxml>
<entities>
<entity>opportunity</entity>
</entities>
<nodes/>
<securityroles/>
<settings/>
<workflows/>
</importexportxml>";