// <copyright file="Postanfrage2Create.cs" company="">
// Copyright (c) 2015 All Rights Reserved
// </copyright>
// <author></author>
// <date>10/21/2015 1:19:49 PM</date>
// <summary>Implements the Postanfrage2Create Plugin.</summary>
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
// </auto-generated>
namespace CrmPackage7.Plugins1
{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
/// <summary>
/// Postanfrage2Create Plugin.
/// </summary>
public class Postanfrage2Create : Plugin
{
/// <summary>
/// Initializes a new instance of the <see cref="Postanfrage2Create"/> class.
/// </summary>
public Postanfrage2Create()
: base(typeof(Postanfrage2Create))
{
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "abaxis_anfrage2", new Action<LocalPluginContext>(ExecutePostanfrage2Create)));
// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
}
/// <summary>
/// Executes the plug-in.
/// </summary>
/// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
/// <see cref="IPluginExecutionContext"/>,
/// <see cref="IOrganizationService"/>
/// and <see cref="ITracingService"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
/// The plug-in's Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the plug-in. Also, multiple system threads
/// could execute the plug-in at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in plug-ins.
/// </remarks>
protected void ExecutePostanfrage2Create(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// TODO: Implement your custom Plug-in business logic.
// Obtain the execution context from the service provider.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "abaxis_anfrage2")
{
try
{
if (entity.Attributes.Contains("abaxis_spieces"))
{
var owningUnit = ((Microsoft.Xrm.Sdk.EntityReference)(entity.Attributes["abaxis_spieces"])).ToString();
entity.Attributes["abaxis_id"] = owningUnit;
}
else
{
entity.Attributes["new_callid"] = "PX100001";
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
}
}
-----------------------------------------------
Above code I have and I need just to update my field "Id" but the value is not populating in the filed. I have tried some ways but could not manage to solve the issue.
The question might be repetitive,sorry for the inconvience but any help will do great!!!