Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Need help to Correct my script.

$
0
0

I m new in CRM. i tried to insert a field after the record is created.
Here is my code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;

namespace AddOrderNumber
{
    public class Class1 : IPlugin 
    {
        public void Execute(IServiceProvider serviceprovider)
        {
            ITracingService tracingservice = (ITracingService)serviceprovider.GetService(typeof(ITracingService));
            IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));

            if (context.InputParameters.Equals("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName == "new_callistyorder")
                {

                    string orderNumber = "ABC-1223-000";
                    try
                    {
                        if (entity.Attributes.Contains("new_nomororder"))
                        {
                            entity.Attributes["new_nomororder"] = orderNumber;
                        }
                        else
                        {
                            entity.Attributes.Add("new_nomororder", orderNumber);
                        }
                    }
                    catch (FaultException<OrganizationServiceFault> ex)
                    {
                        throw new InvalidPluginExecutionException("Plugin Eror", ex);
                    }
                    catch (Exception e)
                    {
                        tracingservice.Trace("System Eror", e.ToString());
                        throw;
                    }
                }
            }
        }
    }
}

But my scripts looks not worked, can you help me to find where is the false from my script?


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>