Reply
Regular Contributor
santro652
Posts: 49
Accepted Solution

Autonumber+WO generated

Hi,

I am facing problem in the below functionality can you suggest me a solution:

My customer is generating Work order from the quotes page when the opportunity is closed.He wants the workorder number to be sequential.

I have created an auto-number field on the opportunity page and this autonumber field i have referenced to a formula field where i have written condition that (If(ispickval(Stage,"opportunity won",Autonumber__c,"NA"), will this generate the numbers in a sequential order? If not can you suggest a workaround.

Regular Contributor
santro652
Posts: 49

Re: Autonumber+WO generated

This does not seem to work as the autonumber will keep on ticking and when the stage is set to opportunity won then the formula will just show th present number for the record..,.. any ideas or solution please help me.

Trusted Contributor
jhurst
Posts: 214

Re: Autonumber+WO generated

Santro652,

 

An Autonumber is a bit different than other fields.  When you create a record, then autonumber is generated for that record instantly, and stored on the record.  So what you describe doing will only hide or display an already assigned autonumber.

 

Another thing to recognize about autonumbers, is that while they most likely will be sequential, they are not guaranteed to be so.  If a save action gets far enough for the autonumber to be created, but then the save is cancelled (though an error, or through some other function) we do not reclaim the used autonumber.  So it is possible to have gaps in the numbers (especially if you use Apex Triggers and other post save logic).

 

Finally, autonumbers are defined such that the system admin can go in and reset or change the autonumber whenever they desire.  The result can be duplicate numbers or gaps in the numbers.

 

What you are describing is a bit different.  In order to guarantee sequential numbers, there are a few ways you can do it (all requiring a varying level of coding):

 

1. You can have an Apex Trigger which determines the last number used and assigns the next number.  The idea would be that you would have the Work Order Number field (either on a Work Order object or as a field on the Opportunity).  You then create a trigger that will query the work order numbers and only bring back the last record (something like select work_order_number__c from Opportunity ORDER BY work_order_number__c DESC LIMIT 1).  You will then have the last number used and you can increment it as desired.

 

2. You can create a new object to hold the Work Order Numbers.  You can use this object to simply store the last number used.  The object will have a single record and a single field.  When you need a new work order number, you query the number field from tyhat record, increment it as desired, save the incremented record to the custom object (so that it will be incremented the next time the query runs), and use the number in the Opportunity or Work Order as needed.

 

3. You can store the number in some other system and then query for it as needed and increment.

 

Depending on your usage, #1 is probably the most straightforward, though you may want to go with #2 for more control over what is stored along wit hthe number (history tracking, etc...).  #3 is probably not feasible, but I wanted to add it here for completeness.

 

Hope this helps.

Jay

Regular Contributor
santro652
Posts: 49

Re: Autonumber+WO generated

Thanks for the suggestion Jay, but the problem is i am using Professional Edition any suggestion for this edition.

Trusted Contributor
jhurst
Posts: 214

Re: Autonumber+WO generated

With Profession Edition, it will be very difficuly, and I do not think that you will be able to 100% guarantee sequential.  You would have to do a similar thing, where you would create a new object type "Work Order" That would be the detail side of a Mater Detail with Opportunity.  Work Order would have a Name field of Type AutoNumber.  When the customer creates a new Work order, the AutoNumber should be sequential (if there is no commit logic like Apex).  

 

The user would then only create the work order when the Opportunity is of the certain stage.