dear team,
i need to see invoice header details are in invoice details sub grid .
invoice header and invoice details are two entities ,relationship is 1:N .please find my plugin script in attachment need some modifications due to getting error.
please suggest me .....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
namespace general_invoice_details
{
public class invoice : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = Context.InputParameters["Target"];
if (entity.LogicalName != "new_invoiceheaderId")
return;
decimal amount = ((Money)entity.Attributes["new_amount"]).Value;
int terms = Convert.ToInt32(entity.Attributes["new_terms"]);
int invoiceday = Convert.ToInt32(entity.Attributes["new_invoiceday"]);
for (int i = 0; 1 < terms; i )
{
try
{
Entity invoicedetails = new Entity();
invoicedetails.LogicalName = "new_invoicedetailsId";
invoicedetails["new_installmentamount"] = new Money(amount / terms);
invoicedetails["new_invoicedate"] = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, invoiceday);
service.Create(invoicedetails);
}
catch (Exception ex)
{
throw new Exception("Exception from invoice plugin" ex.Message);
}
}
}
}
}
}