Dynamics CRM 2011 Portal Development – CrmDataSource

Dynamics CRM 2011 Portal Development

CrmDataSource data source control connects to Dynamics CRM and retrieve EntityCollection

IOrganizationService.RetrieveMultiple(QueryExpression)
IOrganizationService.RetrieveMultiple(QueryByAttribute)

and make it available for other controls to bind to, without requiring code. It supports Select, Create, Update and Delete data.

1. Select

It supports FetchXml and QueryByAttribute to retrieve EntityCollection.

I: FetchXml

FetchXml string can be specified inside <FetchXml></FetchXml> node and parameters can be specified by using <SelectParameters></SelectParameters> node. Parameters in FetchXml must be prefixed with “@” symbol. System.Text.RegularExpressions.Regex.Replace is used to replace the parameter names with a value provided.

Example:


<crm:CrmDataSource ID="CrmDataSource1" runat="server">
 <FetchXml>
 <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
 <entity name="adx_webpage">
 <attribute name="adx_webpageid" />
 <attribute name="adx_name" />
 <attribute name="createdon" />
 <order attribute="adx_name" descending="false" />
 <filter type="and">
 <condition attribute="adx_name" operator="eq" value="@name" />
 </filter>
 </entity>
 </fetch>
 </FetchXml>
 <SelectParameters>
 <asp:Parameter Name="name" DefaultValue="Cases" />
 </SelectParameters>
</crm:CrmDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="CrmDataSource1">

<Columns>
 <asp:BoundField DataField='adx_name' HeaderText="Name" />
 <asp:BoundField DataField='createdon' HeaderText="Created On" />
 </Columns>
 </asp:GridView>

Results:

II: QueryByAttribute

QueryByAttribute can be specified inside <QueryByAttribute></QueryByAttribute> node and parameters can be specified by using <SelectParameters></SelectParameters> node. Parameters specified in QueryByAttribute must be prefixed with “@” symbol.

EntityName, Attributes, Values, ColumnSet, Orders are implicit parameter names, which can be specified as parameter name in <SelectParameters></SelectParameters> node.

While <SelectParameters> can be used to provide values to any parameters defined in <QueryByAttribute></QueryByAttribute> node; <QueryParameters></QueryParameters> values are only added to QueryByAttribute.Attributes and QueryByAttribute.Values.

Example:


<crm:CrmDataSource ID="CrmDataSource1" runat="server">
 <QueryByAttribute EntityName="adx_webpage">
 <Attributes>
 <asp:ListItem Value="@queryAttr"></asp:ListItem>
 </Attributes>
 <ColumnSet>
 <asp:ListItem Value="adx_webpageid"></asp:ListItem>
 <asp:ListItem Value="adx_name"></asp:ListItem>
 <asp:ListItem Value="@timestamp"></asp:ListItem>
 </ColumnSet>
 <Orders>
 <asp:ListItem Text="desc" Value="adx_name"></asp:ListItem>
 </Orders>
 <Values>
 <asp:ListItem Value="Home"></asp:ListItem>
 </Values>
 </QueryByAttribute>
 <SelectParameters>
 <asp:Parameter Name="timestamp" DefaultValue="createdon" />
 <asp:Parameter Name="queryAttr" DefaultValue="adx_name" />
 </SelectParameters>
 <QueryParameters>
 <asp:Parameter Name="adx_name" DefaultValue="Home" />
 </QueryParameters>
 </crm:CrmDataSource>
 <asp:GridView ID="GridView1" runat="server" DataSourceID="CrmDataSource1">
 <Columns>
 <asp:BoundField DataField='adx_name' HeaderText="Name" />
 <asp:BoundField DataField='createdon' HeaderText="Created On" />
 </Columns>
 </asp:GridView>

Result:

2. Update

Advertisements

3 comments on “Dynamics CRM 2011 Portal Development – CrmDataSource

  1. Pingback: Dynamics CRM 2011 Portal Development | Zhongchen Zhou's Blog

  2. We have done a lot of CRM integration for portals Banks and Finance houses and this would have been ideal for the internal ones. For the external ones we synchronised the data into SQL Database and used this as the basis for the portal data layer. It is a little painful but the security guys were a concerned about the opportunity for a DDOS on the internal CRM otherwise.

    • Personally I do not like this ASP.NET WebForm thing, I like MVC much more. But for small and simple implementation, this really allow us to implement much faster.

      Regarding to security concerns, I do believe your implementation is more security. But it is really not that scary, these controls used a lot of cache means after it is retrieved from CRM it is in cache and use a invalid handler to invalid cached entities, so there is not much traffic between the portal and CRM. And it will not tear the CRM down under DOS attack.

      So it is between “duplicate sql/Portal” and “cache/Portal” when there is DOS attack to compare. There is still small overhead to bring items into cache and if they also fake request to the invalid cache handler then items will be fetched from CRM.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s