protected void ExecutePretestingCrm1Create(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// TODO: Implement your custom Plug-in business logic.
// 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
{
Microsoft.Xrm.Sdk.Query.QueryByAttribute querybyattribute = new Microsoft.Xrm.Sdk.Query.QueryByAttribute("abaxis_prefixcounter");
querybyattribute.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("abaxis_prefix1", "abaxis_prefix2", "abaxis_counter");
EntityCollection retrieved = service.RetrieveMultiple(querybyattribute);
//int x = ((OptionSetValue)entity["abaxis_speices"]).Value;
String x = entity.FormattedValues["abaxis_spieces"].ToString();
//var counter = "DC3F0C08-E477-E511-849F-005056830006";
// Guid myid = new Guid("DC3F0C08-E477-E511-849F-005056830006");
//var contract = ((Contract).context.InputParameters["Target"]);
//Guid counter = (Guid)entity.Attributes["abaxis_prefixcounter"];
//Entity newlyCreated = service.Retrieve("Prefix counter", counter, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
//Guid counter = ((Guid)entity.Attributes["abaxis_prefixcounter"]);
//Entity member = service.Retrieve("prefixcounter",myid,new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
var x1 ="";
foreach (var c in retrieved.Entities)
{
x1 = c.Attributes["abaxis_prefix1"].ToString();
}
//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);
}
}
}
}
}
}
---------------------------------------
above is the code which i tried to work on also if you can see i tried to work with Guid too. My problem is how to get the value of another entity in any object and once I get it in object then to retrive it.
Thanks