web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

created details are shows in sub grid

(0) ShareShare
ReportReport
Posted on by 20

requirement 

requirement.png

sales-under.png

services-under.png

invoice header schema names

5822.Untitled.png

invoice details schema names

invoice-details.png

dear team, 

my requirement is when i create a record in invoice header these details are shown in sub grid invoice details.

please suggest me,what can i do what are the steps i will follow.

i have attached my  logic code please look it on.please suggest me real time scenario's websites,blogs to learn . 

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 = (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_invoicedetails";
                        invoicedetails["new_installmentamount"] = new Money(amount / terms);
                        invoicedetails["new_invoicedate"] = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, invoiceday);
                        invoicedetails["new_invoiceId"] = new EntityReference("new_invoice", entity.Id);
                        service.Create(invoicedetails);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Exception from invoice plugin"   ex.Message);

                    }
                }
            }
        }
    }
}
                


            

            
                

 

I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 81 Super User 2026 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#3
11manish Profile Picture

11manish 62

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans