Hi All,
I had a requirement like in the form when the attribute value is "goggle.com" then on save it should change to "yahoo.com". this has to be done when we are updating the form . I have done below for changing the attribute value to "google.com" but now on update it has to change to "yahoo.com".
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
public class MyPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Extract the tracing service for use in debugging sandboxed plug-ins.
// If you are not registering the plug-in in the sandbox, then you do
// not have to add any tracing service related code.
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)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an entity type you are expecting.
// For example, an account. If not, the plug-in was not registered correctly.
if (entity.LogicalName != "account")
return;
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
Entity record = (Entity)context.InputParameters["Target"];
record["attributename"] = "google.com";
// Plug-in business logic goes here.
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("MyPlugin: {0}", ex.ToString());
throw;
}
}
}
}
surya rao
<time>4:40 PM</time>me
<time>4:41 PM</time>surya rao
<time>4:42 PM</time>me
<time>4:42 PM</time>surya rao
<time>4:42 PM</time>me
<time>4:42 PM</time>me
<time>11:59 AM</time>if( record["attributename"] = "google.com")
{
record["attributename"] = "yahoo.com";
}
surya rao
<time>12:00 PM</time>me
<time>12:00 PM</time>surya rao
<time>12:00 PM</time>me
<time>12:00 PM</time>surya rao
<time>12:00 PM</time>me
<time>12:29 PM</time>surya rao
<time>12:29 PM</time>me
<time>12:29 PM</time>Entity record = (Entity)context.InputParameters["Target"];
record["attributename"] = "google.com";
// Plug-in business logic goes here.
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("MyPlugin: {0}", ex.ToString());
throw;
}
}
}
}