Entity
Entity
c
Sorry for typo , i'll send the actual code
Hi,
As per comment f1 is lookup of Entity B but in code you have used f1 has money.
Also, please below highlighted part as f3 declaration seems to be missing;
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Acc
{
public class Acc : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
#region srvc
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
#endregion
tracingService.Trace("Message from tracing Plugin.. step 1");
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth == 1)
{
Entity A = (Entity)context.InputParameters["Target"];
if (A.LogicalName == "A_name")
{
try
{
if (A.Attributes.Contains("f1") && A.Attributes.Contains("f2"))
{
decimal f1 = (A.Attributes.Contains("f1")) ? A.GetAttributeValue<Money>("f1").Value : 0;
Guid f2 = (A.Attributes.Contains("f2")) ? A.GetAttributeValue<EntityReference>("f2").Id : Guid.Empty;
// condition 1
if (f1 == 0 && f2 != null)
{
Entity C = service.Retrieve("c_name", f2, new ColumnSet("f5", "f3"));
int f5 = (C.Attributes.Contains("f5")) ? C.GetAttributeValue<OptionSetValue>("f5").Value : 0;
Guid custid = (C.Attributes.Contains("f3")) ? C.GetAttributeValue<EntityReference>("f3").Id : Guid.Empty;
if (f3 == 804020006) //f3 declaration missing in code
{
Entity acc = service.Retrieve("account", custid, new ColumnSet("f4"));
if (acc.Attributes.Contains("f4") && acc["f4"] != null)
{
acc["f4"] = true;
service.Update(acc);
}
}
}
catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); }
}
}
}
}
}
Also, for better development experience please add multiple tracing inside code.
Thanks,
Pradeep
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156