When
we are retrieving linked entity related information using FetchXML or Query
expression we are using alias attribute to identify the linked entity attributes.
Alias name is prefixed to all linked entity attributes.
Below code snippet will give more information on how to use alias in FetchXML.
Here “service” is an organization service. Click here for more information on how to create organization service
After you run above fetchxml, the way we are reading account related attributes are bit different than customer related attributes.
Reading alias values for different datatypes:
OptionSet Value:
int aliasOptionsetValue = ((OptionSetValue)((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName .new_status"]).Value).Value;
Lookup:
Guid aliasstateGuid = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Id;
string aliasstateName = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Name
Money:
decimal aliasamt = ((Money)fetchCollection.Entities[0].Attributes["AliasAccountName.new_balance"]).Value;
Boolean:
bool aliasisactive = Convert.ToBoolean(fetchCollection.Entities[0].Attributes["AliasAccountName.new_isactive"]);
String:
string aliasString = ((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName.new_name"]).Value.ToString();
You may like below posts
Improving MS CRM Performance
Performance Center in MS CRM 2013
date and time field behavior in MS CRM
Upsert in MSCRM
Locking mechanism in MS CRM
Ticker Symbol Field in MS CRM
Themes in MS CRM
Enable Tracing in MS CRM
Calculated Field in Dynamics CRM 2015
IME Mode in MS CRM
Below code snippet will give more information on how to use alias in FetchXML.
string fetchXML = @"<fetch
version='1.0' output-format='xml-platform' mapping='logical'
distinct='false'>
<entity
name='contact'>
<attribute name='fullname' />
<attribute name='telephone1' />
<attribute name='contactid' />
<attribute name='middlename' />
<attribute name='lastname' />
<attribute name='firstname'
/>
<order
attribute='fullname' descending='false' />
<link-entity name='account' from='accountid' to='parentcustomerid'
visible='false' link-type='outer' alias='AliasAccountName'>
<attribute name='donotphone' />
<attribute name='accountclassificationcode' />
<attribute name='createdon' />
<attribute name='crisp_balance' />
</link-entity>
</entity>
</fetch>
";
FetchExpression fetchExpression = new FetchExpression(fetchXML);
EntityCollection fetchCollection = service.RetrieveMultiple(fetchExpression);Here “service” is an organization service. Click here for more information on how to create organization service
After you run above fetchxml, the way we are reading account related attributes are bit different than customer related attributes.
Reading alias values for different datatypes:
OptionSet Value:
int aliasOptionsetValue = ((OptionSetValue)((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName .new_status"]).Value).Value;
Lookup:
Guid aliasstateGuid = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Id;
string aliasstateName = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Name
Money:
decimal aliasamt = ((Money)fetchCollection.Entities[0].Attributes["AliasAccountName.new_balance"]).Value;
Boolean:
bool aliasisactive = Convert.ToBoolean(fetchCollection.Entities[0].Attributes["AliasAccountName.new_isactive"]);
String:
string aliasString = ((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName.new_name"]).Value.ToString();
You may like below posts
Improving MS CRM Performance
Performance Center in MS CRM 2013
date and time field behavior in MS CRM
Upsert in MSCRM
Locking mechanism in MS CRM
Ticker Symbol Field in MS CRM
Themes in MS CRM
Enable Tracing in MS CRM
Calculated Field in Dynamics CRM 2015
IME Mode in MS CRM
No comments:
Post a Comment