web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Auto Number Based on year.

(0) ShareShare
ReportReport
Posted on by 7,042

Hi Guys,

I want to know how to generate Auto number for a entity based on year.

For Example : Every year Number must start from "ONE" i.e if i created 2000 records in the year 2014 (the auto number is generated up to 2000 approx), in the year 2015 when i create a record the auto number must start from "ONE". 

I don't want to use Autonumber from codeplex or North52 third party tool.

I want to know is it possible to do with plugin or JS. If it so means please suggest me solution for this. 

If not then suggest me how to do with Autonumber using codeplex or North52 or any other third party tools.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at
    RE: Auto Number Based on year.

    Hi Saravana,

    I wanna help you, but can you give more detail about this:

    "For Example : Every year Number must start from "ONE" i.e if i created 2000 records in the year 2014 (the auto number is generated up to 2000 approx), in the year 2015 when i create a record the auto number must start from "ONE". "

    Give a more detail example.

    And yes, usually for running number I use my own plugin easy to build and later maintenance.

    Thanks.

  • Verified answer
    Sayhaitokumar Profile Picture
    7,042 on at
    RE: Auto Number Based on year.

    Hi Aileen,

    My pleasure share the details.

    Let's consider the below scenario.

    I have one entity "Entity A" and has a field "Record Number".

    I want to generate Auto number in that "Record Number" field when user creates a record. If the Autonumber ends on 2000 in the year 2014, then the number must start (Restart) from "ONE" when New Year begins i.e from next year (2015).

    Like this for the every year, the Autonumber must be restarted.

  • Saroj Das Profile Picture
    3,355 on at
    RE: Auto Number Based on year.

    Hi Saravana, what i understand is every year you want your number to be start from 1. I can give a very simple example like, you can do a query to get max number where year is your current year and increase your number. And if you don't get any max number, it means it is new year and you can start the number from 1. And also you have to do some transaction or Locking mechanism to avoid duplicate.

    Hope it clears some of your doubt.

    Thanks,

    Saroj

  • Verified answer
    Sayhaitokumar Profile Picture
    7,042 on at
    RE: Auto Number Based on year.

    Hi Saroj,

    You got my point. The thing is the autonuber may goes to more than what i mentioned above.

  • Saroj Das Profile Picture
    3,355 on at
    RE: Auto Number Based on year.

    Hi Saravanakumar, My doubt is if your number reaches to 2000 before completing the year 2014, then what should be your step. Please give some details.

    Thanks,

    Saroj

  • Verified answer
    Sayhaitokumar Profile Picture
    7,042 on at
    RE: Auto Number Based on year.

    Hi saroj,

    I said that number 2000 is only for example.

    Answer for your question (if your number reaches to 2000 before completing the year 2014) : It must go on (increment .i.e 2001).  

    See for example at the 31st december 2014 11.59 pm if user creates a record, the autonumber is 192000.

    when the next day (1st JAN 2015) , if user creates a record the autonumber starts from ONE.

  • Saroj Das Profile Picture
    3,355 on at
    RE: Auto Number Based on year.

    Hi Saravana, in my above answer i told you the scenario. Let me explain with a query.

    SELECT MAX(autonumField)

     FROM tblCustomer

    WHERE Year='2015'

    In the Above query you are checking the max number in current year (you should have a year field). As it is a new year you will get 0 record. And now you can start from 1. Still if i am not clear. Please give your view.

    Thanks,

    Saroj

  • Sayhaitokumar Profile Picture
    7,042 on at
    RE: Auto Number Based on year.

    Hi Saroj,

    Using SQL Query how to do that? could you please elaborate?

  • Verified answer
    Saroj Das Profile Picture
    3,355 on at
    RE: Auto Number Based on year.

    Hi Saravana, i was trying to explain the logic. You can not write a sql query directly in CRM . If you go for Plugin, then try using LINQ or Query Expression or you can go for Javascript ODATA. It's depend on your choice.

    Thanks,

    Saroj

  • Community Member Profile Picture
    on at
    RE: Auto Number Based on year.

    Hi Saravana,

    I am sure Aileen has a concrete example -

    Below is my theoretical approach:)

    One of the ways is to have an entity that has a few attributes to track the year and Auto number with Entity name . Use a Plugin and register in which ever entity(entities) you would like to use this. (Thinking if we have more than one entity)

    Based on the entity and triggering point - get the current auto number for that entity - update the Attribute in the entity - ensure to increment the auto number so next entity instance will not use the same number.

    As part of the logic - check the current date/time - reset the counters to '1' when the year changes (current year changes to next year).

    Let us know how it goes.

    harihar

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans