How to Return Multiple Value from method
====================================================================
private static decimal[] FetchResult(Guid OpportunityID, IOrganizationService service)
{
Entity postImageEntity = new Entity();
string FetchOpportunityProduct = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
<entity name='opportunityproduct'>
<attribute name='ti_extendedenhancement' alias='totalservicecostamount_sum' aggregate='sum' />
<attribute name='ti_extendedserviceamount' alias='totalamount_sum' aggregate='sum'/>
<link-entity name='opportunity' from='opportunityid' to='opportunityid' alias='ab'>
<filter type='and'>
<condition attribute='opportunityid' operator='eq' value='{0}' />
</filter>
</link-entity>
</entity>
</fetch>";
decimal TotalValue = 0; // Enhancement Amount
decimal toatlamt = 0; // Service Amount
FetchOpportunityProduct = string.Format(FetchOpportunityProduct, OpportunityID);
EntityCollection result = (EntityCollection)service.RetrieveMultiple(new FetchExpression(FetchOpportunityProduct));
if (result.Entities.Count > 0)
{
foreach (Entity c in result.Entities)
{
if (c.Attributes.Contains("totalservicecostamount_sum"))
{
decimal aggregate2 = ((Money)((AliasedValue)c.Attributes["totalservicecostamount_sum"]).Value).Value;
TotalValue = aggregate2;
}
else
{
TotalValue = 0;
}
if (c.Attributes.Contains("totalamount_sum"))
{
decimal aggregate1 = ((Money)((AliasedValue)c.Attributes["totalamount_sum"]).Value).Value;
toatlamt = aggregate1;
}
else
{
toatlamt = 0;
}
}
}
return new decimal[] { TotalValue, toatlamt };
}
====================================================================
private static decimal[] FetchResult(Guid OpportunityID, IOrganizationService service)
{
Entity postImageEntity = new Entity();
string FetchOpportunityProduct = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
<entity name='opportunityproduct'>
<attribute name='ti_extendedenhancement' alias='totalservicecostamount_sum' aggregate='sum' />
<attribute name='ti_extendedserviceamount' alias='totalamount_sum' aggregate='sum'/>
<link-entity name='opportunity' from='opportunityid' to='opportunityid' alias='ab'>
<filter type='and'>
<condition attribute='opportunityid' operator='eq' value='{0}' />
</filter>
</link-entity>
</entity>
</fetch>";
decimal TotalValue = 0; // Enhancement Amount
decimal toatlamt = 0; // Service Amount
FetchOpportunityProduct = string.Format(FetchOpportunityProduct, OpportunityID);
EntityCollection result = (EntityCollection)service.RetrieveMultiple(new FetchExpression(FetchOpportunityProduct));
if (result.Entities.Count > 0)
{
foreach (Entity c in result.Entities)
{
if (c.Attributes.Contains("totalservicecostamount_sum"))
{
decimal aggregate2 = ((Money)((AliasedValue)c.Attributes["totalservicecostamount_sum"]).Value).Value;
TotalValue = aggregate2;
}
else
{
TotalValue = 0;
}
if (c.Attributes.Contains("totalamount_sum"))
{
decimal aggregate1 = ((Money)((AliasedValue)c.Attributes["totalamount_sum"]).Value).Value;
toatlamt = aggregate1;
}
else
{
toatlamt = 0;
}
}
}
return new decimal[] { TotalValue, toatlamt };
}
No comments:
Post a Comment