Recent Posts

ads

How to create same records in parent and chaild entity using Microsoft CRM plugin?

create same records in parent and chaild entity :


At the point when the formation of parent entity then the chaild record consequently planning similar information through plugins.

         Here I will take offer is a parent substance and suboffer is a chaild element.

Dynamic365 plugins



Create same records In parent and chaild Plugin :

     I however every one of you realize the how to enlist the module enrollment beneath I will give the which activity and message you accomplished for the underneath code. 

Message : Create
Stage   : post_operation

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using System.ServiceModel; namespace offerdetails {     public class offer : 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));             // The InputParameters collection contains all the data passed in the message request.             if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)             {                 try                 {                     // Obtain the target entity from the input parameters.                     Entity offer = (Entity)context.InputParameters["Target"];                     Entity suboffer = new Entity("lvt_suboffer");                     IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));                     IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);                     if (offer.Contains("lvt_name"))                     {                         //suboffer.Attributes["lvt_name"] = offer.Attributes["lvt_name"];                         suboffer["lvt_name"] = (string)offer["lvt_name"];                     }                     if (offer.Contains("lvt_productid"))                     {                                                //suboffer.Attributes["lvt_productid"] = suboffer.Attributes["lvt_productid"];                         suboffer["lvt_productid"] = (Object)offer["lvt_productid"];                     }                     if (offer.Contains("lvt_couponcode"))                     {                        // suboffer.Attributes["lvt_couponcode"] = suboffer.Attributes["lvt_couponcode"];                         suboffer["lvt_couponcode"] = (Object)offer["lvt_couponcode"];                     }                     if (offer.Contains("lvt_address"))                     {                         //suboffer.Attributes["lvt_address"] = suboffer.Attributes["lvt_address"];                         suboffer["lvt_address"] = (string)offer["lvt_address"];                     }                     if (offer.Contains("lvt_email"))                     {                         //suboffer.Attributes["lvt_email"] = suboffer.Attributes["lvt_email"];                         suboffer["lvt_email"] = (string)offer["lvt_email"];                     }                     //contact["lvt_employe"] = new EntityReference(employeEntity.LogicalName, employeEntity.Id);                     Guid subofferid = service.Create(suboffer);                 }                                catch (Exception Ex)                 {                     throw new InvalidPluginExecutionException(Ex.Message);                 }             }         }     } }

Post a Comment

0 Comments