locked
Custom Entity... RRS feed

  • Question

  • Hi...

    I have a custom entity and I want to manipulate it through a plugin...   the entity logical name is "new_projet"...

    the field is an interger "new_Numrodejob"...

    so here is my code...

    // Microsoft Dynamics CRM namespace(s)
    using Microsoft.Xrm.Sdk;

    namespace BarretteStructuralPlugin
    {
        public class accountManager : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                // Obtain the execution context from the service provider.
                Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));      

                // The InputParameters collection contains all the data passed in the message request.
                if (context.InputParameters.Contains("Target"))
                {
                    // Obtain the target entity from the input parameters.
                    Entity entity = (Entity)context.InputParameters["Target"];
                                            
                    switch(entity.LogicalName)
                    {                      

                        case "account":
                            GelServiceContractClient gelWebService = new GelServiceContractClient();
                            SoumissionArgs argsSoum = new SoumissionArgs();

                            argsSoum.InfoRevision = new InfoSoumGenerale();
                            argsSoum.Prefixe = string.Empty;

                            int? numeroSoumission;
                            numeroSoumission = gelWebService.NextSubmissionNumber(argsSoum);
                            entity["accountnumber"] = numeroSoumission.ToString();

                            Money annualRevenue = new Money(1000);
                            //entity.Attributes.Add("revenue", annualRevenue);
                            entity["revenue"] = annualRevenue;

                            Money montantSoumEnCours = new Money(1000000);
                            //entity.Attributes.Add("new_montantssoumissionencours", montantSoumEnCours);
                            entity["new_montantssoumissionencours"] = montantSoumEnCours;
                                                      
                            break;

                        case "new_projet ":
                            int numeroDeJob = 100;
                            entity["new_Numrodejob"] = numeroDeJob;

                            break;
                    }       
                }
            }
        }
    }

    why the code in "case "new_projet": is not working...  

    The plugin is register to the create message ans primary entity to none

    Best regards,

    Steph

    Tuesday, October 6, 2015 7:37 PM

Answers

  • Hello,

    1. Remove space - use "new_projet" instead of "new_projet ".

    2. Use lowercase referring fields - entity["new_numrodejob"] instead of entity["new_Numrodejob"].


    Dynamics CRM MVP
    My blog

    • Marked as answer by stedes_dev Tuesday, October 6, 2015 8:17 PM
    Tuesday, October 6, 2015 7:56 PM
    Moderator

All replies

  • Hello,

    1. Remove space - use "new_projet" instead of "new_projet ".

    2. Use lowercase referring fields - entity["new_numrodejob"] instead of entity["new_Numrodejob"].


    Dynamics CRM MVP
    My blog

    • Marked as answer by stedes_dev Tuesday, October 6, 2015 8:17 PM
    Tuesday, October 6, 2015 7:56 PM
    Moderator
  • thanks alot...

    Always  dump think... 

    Regards,

    Steph

    Tuesday, October 6, 2015 8:17 PM