I have an entity called new_manufacturer and its display name is Manufacturer. I am trying to create a plugin where the input field called new_userinput on the main form of the new_manufacturer entity is checked to see if it contains the text "Test" when the user clicks the Save button.
If it does contain the text "Test" then another field called new_viewuserinput on the form will be populated with the text "Test Successful". Below is my code:
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Dynamics365CrmPlugin
{
public class CrmPluginIPlugin:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "new_manufacturer")
{
return;
}
IOrganizationServiceFactory serviceFactory = null;
serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
// Check UserInput field in a form in Manufacturer entity for the phrase Test.
if (entity.LogicalName == "new_manufacturer")
{
if (entity.Attributes["new_userinput"].ToString().Trim() == "Test")
{
entity.Attributes["new_viewuserinput"] = "Test Successful";
}
}
}
catch
{
}
}
}
}
}
I registered the plugin and created the steps. I set Message to Update, set Primary Entity to new_manufacturer, chose Post Operation, set Execution Mode to Synchronous, and set Deployment to Server.
Please point out any thing you see that could be causing my code not to do what it was written to do, thanks.
*This post is locked for comments
I have the same question (0)