Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:45:19+00:00 2026-05-28T00:45:19+00:00

I have a plugin registered for when an account is created or updated, this

  • 0

I have a plugin registered for when an account is created or updated, this is registered for the post stage.

The plugin works fine when a user creates or updates an account through the CRM interface, however when an account is created uging the API the plugin fails with the ever helpful ‘server was unable to process the request’ message. if an account is updated through the api the plugin also works correctly.

anyone have any ideas why?

UPDATE:

here is the create code

  account = new CrmService.account();

                account.ownerid = new CrmService.Owner();
                account.ownerid.Value = new Guid("37087BC2-F2F0-DC11-A856-001E0B617486");
                account.ownerid.type = CrmService.EntityName.systemuser.ToString();

                account.name = model.CompanyName;
                account.address1_line1 = model.Address1;
                account.address1_line2 = model.Address2;
                account.address1_stateorprovince = model.County;
                account.address1_country = model.Country;
                account.address1_city = model.TownCity;
                account.address1_postalcode = model.PostCode;
                account.new_companytype = new CrmService.Picklist();

                switch (model.SmeType)
                {
                    case SmeType.Micro:
                        account.new_companytype.Value = 1;
                        break;
                    case SmeType.Small:
                        account.new_companytype.Value = 2;
                        break;
                    case SmeType.Medium:
                        account.new_companytype.Value = 3;
                        break;
                    default:
                        break;
                }

                account.new_balancesheettotal = new CrmService.CrmMoney();
                account.new_balancesheettotal.Value = preQualModel.BalanceSheetGBP;
                account.revenue = new CrmService.CrmMoney();
                account.revenue.Value = preQualModel.SalesTurnoverGBP;
                if (model.Website != null)
                {
                    account.websiteurl = model.Website.ToString();
                }
                account.numberofemployees = new CrmService.CrmNumber();
                account.numberofemployees.Value = (int)preQualModel.NumEmployees;


                accountGuid = svc.Create(account);
                account.accountid = new CrmService.Key();
                account.accountid.Value = accountGuid;

Here is the plugin code:

public void Execute(IPluginExecutionContext context)
    {
        DynamicEntity entity = null;

        // Check if the InputParameters property bag contains a target
        // of the current operation and that target is of type DynamicEntity.
        if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
           context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
        {
            // Obtain the target business entity from the input parmameters.
            entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];

            // TODO Test for an entity type and message supported by your plug-in.
            if (entity.Name != EntityName.account.ToString()) { return; }
            // if (context.MessageName != MessageName.Create.ToString()) { return; }

        }
        else
        {
            return;
        }

        if (entity!=null && !entity.Properties.Contains("address1_postalcode"))
        {
            return;
        }

        if (context.Depth > 2)
        {
            return;
        }

        try
        {
            // Create a Microsoft Dynamics CRM Web service proxy.
            // TODO Uncomment or comment out the appropriate statement.

            // For a plug-in running in the child pipeline, use this statement.
            // CrmService crmService = CreateCrmService(context, true);

            // For a plug-in running in the parent pipeline, use this statement.
            ICrmService crmService = context.CreateCrmService(true);

            #region get erdf area from database

            string postCode = entity.Properties["address1_postalcode"].ToString();
            postCode = postCode.Replace(" ", ""); //remove spaces, db stores pcodes with no spaces, users usually enter them, e.g b4 7xg -> b47xg
            string erdfArea = "";

            SqlConnection myConnection = new SqlConnection(@"REDACTED");

            try
            {
                myConnection.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                SqlDataReader myReader = null;
                SqlCommand myCommand = new SqlCommand("select ErdfAreaType from dim.Locality WHERE PostCode = '" + postCode+"'",
                                                         myConnection);
                myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    erdfArea = myReader["ErdfAreaType"].ToString();                        
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                myConnection.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            #endregion

            entity.Properties["new_erdfarea"] = erdfArea;                

            crmService.Update(entity);

        }
        catch (System.Web.Services.Protocols.SoapException ex)
        {
            throw new InvalidPluginExecutionException(
                String.Format("An error occurred in the {0} plug-in.",
                   this.GetType().ToString()),
                ex);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:45:20+00:00Added an answer on May 28, 2026 at 12:45 am

    Turns out this was due to me expecting data that was not there due to some weird behaviour in CRM.

    I was taking the dynamicEntity passed to the plugin like so

    entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
    

    But this was missing critical things like accountid. fixed it by using the PostEntityImage entity instead, which had all of the expected data like so

    entity = (DynamicEntity)context.PostEntityImages[ParameterName.Target];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a IOS application created through phonegap framework. I have registered a particular
I have the following facebook registration plugin that lets user register through their FB
I have Dynamics CRM 4.0 installed and wrote a plugin, registered it, and setup
I have a plugin that is loaded by this application.. This plugin calls some
I have a bbcode plugin for wordpress. But for some reason, if I post
This post relates to WordPress and CIMY User Extra Fields. I do not think
I have a plugin written that is registered for the DeliverIncoming message on the
this is a working example of a plugin that I have written for CRM
I have a .xll plugin that registered a few functions which we use in
I have findbugs plugin for eclipse which when run on my project will show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.