Within the company I'm working for I've created a new entity in Microsoft Dynamics CRM 2013 called Issue, within the entity Issue there is a sub grid where users can add records from the entity Cost To Business.
The purpose is that users add the records when needed. I'm now using a FetchXML Query with a C# Plugin so that I can retrieve the Cost Attribute that is related to each record in the subgrid so that I can populate a Total Cost Field.
So far I have the following Query
Guid orderID = (Guid)((Entity)context.InputParameters["Target"]).Id;
string fetchxml =
@"<fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'>
<entity name='new_issue'>
<attribute name='new_issueid'/>
<attribute name='new_name'/>
<attribute name='createdon'/>
<order descending='false' attribute='new_issueid'/>
<filter type='and'>
<condition attribute='new_issueid' operator='eq' value='" + orderID + @"'/>
</filter>
<link-entity name = 'new_costtype' alias='ac' to='new_issueid' from='new_costtypeissueid'>
<link-entity name='new_costtobusiness' alias='ad' to='new_costtobusinesscosttypeid' from='new_costtobusinessid'>
<attribute name='new_coststring'/>
</link-entity>
</link-entity>
</entity>
</fetch>";
However the Query can't be returning anything as the following code is not getting executed.
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxml));
{
if (result != null && result.Entities.Count > 0)
{
List<int> _product = new List<int>();
foreach (Entity _entity in result.Entities)//loop through every record
{
costToBusiness = ((AliasedValue)_entity.Attributes["ad.new_coststring"]).Value.ToString();
total = (total) + Convert.ToInt32(costToBusiness);
}
if(entity.Attributes.Contains("new_businessstring"))
{
entity.Attributes["new_businessstring"] = currencyName + total.ToString();
costToBusiness = "";
total = 0;
currencyName = "";
}
else
{
entity.Attributes.Add("new_businessstring", currencyName + total.ToString());
costToBusiness = "";
total = 0;
currencyName = "";
}
}
Does anyone have a reason/suggestion as to why this is happening? Thanks in advance
S.Harrison