Hi Devs,
I have a simple fetch that retrieves [Opportunity Lines associated with Customer Asset ].
Question
How do i retrieve the [Customer Asset] fields in my for each loop in early bound.
try
{
string fetchQuery = @"
<fetch mapping='logical'>
<entity name='opportunityproduct' >
<attribute name='opportunityproductid' />
<filter type='and' >
<condition attribute='opportunityid' value='{zzz}' operator= 'eq'/>
</filter>
<link-entity name='msdyn_customerasset' alias='ap' link-type='inner' to='tac_customerlift' from='msdyn_customerassetid' >
<attribute name='tac_liftno' />
<attribute name='tac_liftid' />
</link-entity>
</entity>
</fetch>";
tracingService.Trace("Retrieved FetchXML Query");
fetchQuery = fetchQuery.Replace("zzz", OpportunityID.ToString());
EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchQuery));
// Run the query with the FetchXML
try
{
if (results.Entities.Count > 0)
foreach (var opportunitylines in results.Entities)
{
OpportunityProduct opplines = opportunitylines.ToEntity<OpportunityProduct>();
msdyn_customerasset CustAssett = opportunitylines.ToEntity<msdyn_customerasset>(); // Do i need to add Customer Asset to the entity collection just after the fetch ?
opplines.tacagreement = AgreementReference;
CustAssett.tac_flag = true;
CustAssett.tac_LiftID = "updated";
}
Error Message
Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): CopyOpportunityLines.CopyOpportunityLines: System.NotSupportedException: Cannot convert entity opportunityproduct to msdyn_customerasset
at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.<Execute>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
-- End stack trace --
*This post is locked for comments