Auto Number Plugin RRS feed

  • Question

  • Hi All,

    I am new to CRM Plugins, Now I am in need of writing plugin for generation unique Id for every record created. This should be done using plugin. Can any one please send me the code, I am using developer tool kit .

    Thanks In Advance ...

    Thursday, June 26, 2014 11:37 AM

All replies

  • Hi,

    There are many solution available over codeplex , did you try to consider them.

    you can also check




    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, June 26, 2014 11:53 AM
  • Hi All,

    I wrote the below logic for generating auto number for code entity , but it is giving count and setting value on number field . but my requirement is to add 1000 as series before that count .

    Please help me how can I do this ...


    classPreCodeCreate: Plugin





    ///Initializes a new instance of the <see cref="PreCodeCreate"/>class.





    IPluginExecutionContextcontext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));


    IOrganizationServiceFactoryserviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));


    IOrganizationServiceservice = serviceFactory.CreateOrganizationService(context.UserId);


    //  IOrganizationService ServiceProxy = ServiceProxy


    if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] isEntity)



    Entityentity = (Entity)context.InputParameters["Target"];


    QueryExpressionquery = newQueryExpression("new_code");

                    query.ColumnSet =



    EntityCollectionresult = service.RetrieveMultiple(query);



    inttotalRecords = result.Entities.Count;


    //Convert.ToInt32(entity.Attributes["new_serialnumber"]) + 1;


    varfianlresult = totalRecords + 1;


    intseries = 1000;


    "new_ogscode"] = series + fianlresult;





    Friday, June 27, 2014 7:51 AM
  • Try this

    string series = "1000";

     entity.Attributes["new_ogscode"] = series + fianlresult;

    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, June 27, 2014 10:03 AM
  • Hi,

    Codeplex solution:


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Yogesh Vijay Mulay

    Monday, June 30, 2014 9:07 AM
  • Hi All,

    Is auto number and Unique Id generation is same ?

    Tuesday, July 1, 2014 6:23 AM
  • Hi Pal,

    This idea is also not working , now my requirement changed I need to get some value from a field followed by count number.

    How to get the value of the related entity field ad append that to the autonumber ?

    Thank You

    Wednesday, July 2, 2014 11:41 AM
  • You can retreive the value of field using query expression, linq, fetchxml or sql statement. There is another method know as query by attribute which is below:-

    /  Create query using QueryByAttribute.
                        QueryByAttribute querybyattribute = new QueryByAttribute("account");
                        querybyattribute.ColumnSet = new ColumnSet("name", "address1_city", "emailaddress1");
                        //  Attribute to query.
                        //  Value of queried attribute to return.
                        //  Query passed to service proxy.
                        EntityCollection retrieved = _service.RetrieveMultiple(querybyattribute);
                        //  Iterate through returned collection.
                        foreach (var c in retrieved.Entities)
                            string oName = c.Attributes["name"];

    //If there is always one record to get then you can also use following instead of last 4 lines of code which are Italic

    string oName = c.Attributes[0]["name"];


    Regards Faisal

    Wednesday, July 2, 2014 1:03 PM
  • Hi All,

    I am having a requirement like to get the value of the location code field on locations entity which has 1:N relationship(placed as a grid)  with the current entity where we need to generate the auto number and concatenate it with the series number. How can we write this . Please provide me the code which helps me a lot .

    Its urgent ...

    Thank You

    Monday, July 7, 2014 11:34 AM