Asked by:
Plug-in For Auto Number

Question
-
Hello there ,
Thanks in Advance....
-----------------------------------
my problem is i want to make plug-in for auto number generation on account entity , i have custom field Auto number ,
i have to fire this plug-in when a new account is created .
so can any body please post the code for me ....
Wednesday, June 6, 2012 9:17 AM
All replies
-
Hi,
you can use some simple java script to populate your Field with Auto Number.
function autonum() { var an = Xrm.Page.data.entity.attributes.get("accountnumber").getValue(); if (an == null || an == " ") { var m_n = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"); var d = new Date(); var c_d = d.getDate(); var c_m = d.getMonth(); var c_y = d.getFullYear(); var num = Math.floor(Math.random()*101); Xrm.Page.getAttribute("accountnumber").setValue(c_y+""+m_n[c_m]+""+c_d+""+num); Xrm.Page.getAttribute("accountnumber").setSubmitMode("always"); } }
This code format will be "year month date two digit random number" if you want you can use time value with "seconds" to generate more random unique Value for your entity.
- Purush(MCTS) Rogrand Consulting(www.rogrand.com)China
Wednesday, June 6, 2012 9:42 AM -
Hi,
If you google or bing you find intersting things...
I think this solution can fit for you:
http://m-atif.blogspot.pt/2011/12/auto-number-solution-for-dynamics-crm.html
Cheers
Mario Andre Moreira
Wednesday, June 6, 2012 10:29 AM -
There are many good solutions out there. Probably easier to just download something http://crm2011autonumber.codeplex.com/
- Proposed as answer by Sven Vanoirbeek Wednesday, June 6, 2012 11:44 AM
Wednesday, June 6, 2012 11:44 AM -
Hii thanks to all of you for ur quick reply but i want plug-in code i dont need any solution
i have to do it from plug-in only... thats the client requirement . so please post the code of plug-in
Wednesday, June 6, 2012 1:27 PM -
- Proposed as answer by Sven Vanoirbeek Wednesday, June 6, 2012 1:40 PM
Wednesday, June 6, 2012 1:40 PM -
Thanks Sven For ur reply but i have few doubts regarding the link u given.
In this example they created 2 new entities . but in my scenario i dont required that .
As per my scenario i have to fire a plug-in only when new account is created...
so please post the code. i am beginner in CRM and the code given in link was complicated so please help me out .
Wednesday, June 6, 2012 1:55 PM -
Entity entity = (Entity)context.InputParameters["Target"];
//Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName == "xrm_trackntrace")The above part is the part where you check if the entity is of the type "account".
If you don't want an extra entity to store your current value of your autonumbering then you'll need to look at the last created account. This is however more error prone IMHO. I would advise to try and understand the code in the example. Just copy / pasting the code will not help you because you will not understand what's actually happening. The CRM SDK is a good resource to start learning CRM development. http://www.microsoft.com/en-us/download/details.aspx?id=24004
- Proposed as answer by Sven Vanoirbeek Wednesday, June 6, 2012 8:58 PM
Wednesday, June 6, 2012 2:03 PM -
Thanks Sven For ur Valuable guidance i will try my level best to make this plug-in .
If any error occurred or help required will contact you
Thanks Again.
Wednesday, June 6, 2012 2:13 PM -
Wajed,
You can use existing AutoNumber solution such as Advanced CRM 2011 Auto Number which can be downloaded from http://advcrm2011autonumber.codeplex.com
It works on any CRM environment (On-Premise, Online and Partner Hosted). It also works on Load Balancing environment and supports complex auto number format. There are a few people in this forum already downloaded it and found it to be pretty good.
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Proposed as answer by Dimaz Pramudya (www.xrmbits.com) Thursday, June 7, 2012 4:20 AM
- Edited by Dimaz Pramudya (www.xrmbits.com) Thursday, June 7, 2012 4:20 AM
Thursday, June 7, 2012 4:20 AM