Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

invoice header details are appear in invoice details sub grid using plugins

(0) ShareShare
ReportReport
Posted on by 20

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);

                    }
                }
            }
        }
    }
}
                


            

            
                

WhatsApp-Image-2020_2D00_01_2D00_19-at-9.17.15-PM.jpegWhatsApp-Image-2020_2D00_01_2D00_19-at-9.16.47-PM.jpeg

  • tctsl1013 Profile Picture
    tctsl1013 20 on at
    RE: invoice header details are appear in invoice details sub grid using plugins

    Hii,

    dear sir/Madam thank you so much for your reply error got cleared....

  • Verified answer
    Inogic Profile Picture
    Inogic 438 on at
    RE: invoice header details are appear in invoice details sub grid using plugins

    Hi,

    You have to typecast the Target into an entity. Please convert the Target into an entity as shown below:

    Entity entity = (Entity)context.InputParameters["Target"];

    typecast.jpg

    Hope this helps.

    Thanks!

  • tctsl1013 Profile Picture
    tctsl1013 20 on at
    RE: invoice header details are appear in invoice details sub grid using plugins

    i tried but no luck sir...still error not cleared

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: invoice header details are appear in invoice details sub grid using plugins

    Replace

    Entity entity = Context.InputParameters["Target"];

    with

    Entity entity = context.InputParameters["Target"];

    C# is case sensitive language.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans