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 8148871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:43:52+00:00 2026-06-06T14:43:52+00:00

I am attempting to write my first Dynamics Crm 2011 plugin. I have therefore

  • 0

I am attempting to write my first Dynamics Crm 2011 plugin.

I have therefore downloaded the CRM11 sdk and taken a look at the plugin samples. I have finally got my first plugin installed and registered using the supplied tools (quite a steep learning curve on that one, for me at least).

I started with the basics and compiled up the “Account Number Plugin” that is provided in the samples and used the registration tool. All was reported as being installed successfully but on creating a new account the generated account number was not showing up at all. I initially thought that the plugin was not installed correctly but after noticing that the code would throw an error if the account number was already present I set about trying to get the plugin to raise the error. This worked first time so I am happy that the installation is correct.

After looking at the sample code I am lost as to how the generated account number is saved back to Dynamis Crm.

// An accountnumber attribute should not already exist because it is system generated.

if (entity.Attributes.Contains("accountnumber") == false)    
{    
    // Create a new accountnumber attribute, set its value, and add
    // the attribute to the entity's attribute collection.

    Random rndgen = new Random();  
    entity.Attributes.Add("accountnumber", rndgen.Next().ToString());    
}    
else     
{    
    // Throw an error, because account numbers must be system generated.    
    throw new InvalidPluginExecutionException("The account number can only be set by the system.");    
}

Looking through some of the other samples I noticed some additional code that appears to be called to create new entities. I adjusted this and copied it into the new account number code, deployed and the account number was generated as expected.

IOrganizationServiceFactory serviceFactory  = (IOrganizationServiceFactory)

    serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

service.Update(entity); // Originally - service.Create(entity);

Is this an error in the sample code or am I doing something wrong? If this code is not required when does the entity submit its changes to the database?

  • 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-06-06T14:43:53+00:00Added an answer on June 6, 2026 at 2:43 pm

    Just worked it out. You need to register this plugin as a “Pre-Operation” step.

    That will teach me for leaving the registration tool to its defaults. With it set to “Pre-Operation” the settings of the entity are changed before saving. Therefore you do not need to call save again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write my first jQuery plugin to query multi-dimensional arrays of complex
I have been attempting to write a VBA Script that can parse out other
I'm attempting to write my first custom Cocoa Framework and I want to expose
I'm attempting to write a TinyURL like clone in ASP.NET MVC as a first
I'm attempting to write my first unity script. This is the code for a
I am attempting to write a JQuery to focus on the first visible, enabled
I'm attempting to write my first php/mysql page and am running into a SQL
I'm attempting to write a widget for DotNetNuke in C#. This is my first
I am attempting to write my first implementation of databinding in a WPF form.
I attempting to write a simple JQuery search. This is what I have so

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.