Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

plugin error

$
0
0

trying update a field based on another field.during update post-syn

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred in MyPlug-in.Detail:

public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
try
{
if (context.Depth == 1)
{

IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

// Entity contact = new Entity("contact");

// Obtain the target entity from the input parmameters.
//EntityReference entity = (EntityReference)context.InputParameters["Target"];
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity account = (Entity)context.InputParameters["Target"];


ColumnSet cols = new ColumnSet(new String[] { "address1_city", "address1_country" });

account = service.Retrieve(account.LogicalName, account.Id, cols);

if (account != null)
{
if (account.Attributes.Contains("address1_city") == false)
{
//Random rndgen = new Random();
account.Attributes["address1_city"] = "none";
}
else
{
account["address1_city"] = "Usa";
}service.Update(account);
}}}}
catch (FaultException<OrganizationServiceFault> ex)
{throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex.InnerException);}catch (Exception e) { Console.WriteLine(e.Message); }
}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>