
Hi,
What I wanted to achieve is below -
On each Quote Save, will get all the quotedetails for the given quote,
for each quote detail
set quotedetail tax as 12 and extendedamount as amount 12
on quote which I got from context, set the totaltaxamount as quotedetailcount*12 5
There are two issues, I am seeing with this -
1. This plugin is getting called multiple times
2. I couldn't able to save the quotedetail records using the relatedEntities. How I can do this.
Appreciate any help on this. Thanks.
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
tracingService.Trace("inside update test plugin");
Entity entityFromContext = (Entity)context.InputParameters["Target"];
try
{
EntityCollection entityCollection = GetLineItems(entity, service);
Money money = new Money();
decimal d = 0;
List updateLineEntityList = new List();
foreach (Entity lineEntity in entityCollection.Entities)
{
lineEntity["tax"] = new Money(12);
Money money1 = (Money)lineEntity["amount"];
lineEntity["extendedamount"] = new Money(12 money1.Value);
updateLineEntityList.Add(lineEntity);
d = 12;
}
entityFromContext.RelatedEntities.Add(new Relationship("quote_details"), new EntityCollection(updateLineEntityList));
entityFromContext["totaltax"] = new Money(d 5);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
}
}
}
private EntityCollection GetLineItems(Entity entity, IOrganizationService service)
{
QueryExpression query = new QueryExpression("quotedetail");
string[] columns = { "extendedamount","tax","amount" };
var columnList = new List();
columnList.AddRange(columns);
columnList.Add("quoteid");
query.ColumnSet = new ColumnSet(columnList.ToArray());
FilterExpression filter = new FilterExpression();
filter.AddCondition("quoteid", ConditionOperator.Equal, entity.Id);
query.Criteria = filter;
EntityCollection entityCollection = service.RetrieveMultiple(query);
return entityCollection;
}
} Hi Radi,
Can you please let us know the version of your instance? I need to check whether we are able to use rollup or calculated columns.
Let me know if I can provide more details for you.
Thanks
Regards,
Abdul Wahab
Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
Direct/WhatsApp:+923323281237
E-mail: abdulwahabubit@outlook.com
Skype: abdul.wahabubit
Linkedin: www.linkedin.com/.../