I am working on a crm plugin MS crm 2011.
What I need is : To get value of 3 fields from let's say "Counter" entity and setting it in my current entity let's say "Testingcrm"
when I save few of the details on my "Testingcrm" entity in front end I need to populate few of my fields in "Testingcrm" to be updated with values from "Counter" entity.
I have created a plugin as CREATE and PRE OPERATION.
Any help will be much appreciated!!!
-----------------------------------------
// 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 == "new_testingcrm1")
{
try
{
//int x = ((OptionSetValue)entity["abaxis_speices"]).Value;
String x = entity.FormattedValues["abaxis_spieces"].ToString();
Guid counter = ((EntityReference)entity["abaxis_prefixcounter"]).Id;
//Entity member = service.Retrieve("prefixcounter",counter,new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
//var x1 = member.Attributes["abaxis_prefix1"];
entity.Attributes["new_medid"] = counter;
/*if (x.Contains("MED"))
{
entity.Attributes["new_medid"] = "x1";
}
else
{
entity.Attributes["new_medid"] = "x1";
}*/
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}