Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

created details are shows in sub grid

Posted on by 20

requirement 

4150.invoice-details.png

3225.requirement.png

7848.sales-under.png

invoice header schema names

5381.services-under.png

invoice details schema names

3108.Untitled.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);

                    }
                }
            }
        }
    }
}
                


            

            
                

 

  • RE: created details are shows in sub grid

    Hi

    If the plugin is populating the lookup that the subgrid is using, the records should be displayed by default.

    All you need to do is:

    - Setup a view for the invoice details that contains all the data you require and set it to be used in your subgrid

    - make sure the grid is using the relationship that you are populating

    As the create is being made by the plugin, you might also have to force a refresh on the form after.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans