0

I have Quote number field so when printing PDF Number is in format 55-JD-2012, 56-JD-2012,57-JD-2012 etc. So 55, 56,57 are Quote numbers which are automatically generated.I am interested in reseting this first value which is Quote number value and that is the field of course from Quote module. I would like it to reset it for this year so when printing PDF I will be able to get this as output: 55- JD -2013, 56 -JD -2013 etc. At the moment I am getting as an output number for 1 bigger than my last Quote number currently over 500.

How to reset this counter in which file or where?

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
Stefke
  • 141
  • 8
  • 19

1 Answers1

1

The Quote Number field in SugarCRM is an auto-increment field (the incrementing takes place not in SugarCRM itself, but in the database). It also has an index on the field with a unique constraint.

Because of this, the field can't be reset simply. The Quote Number must be unique, and it must auto-increment.

In order to have a resettable Quote Number field in SugarCRM, you would need to create a new field with some special logic and/or create a SugarCRM package that customizes the behavior of either the default Quote Number field, or a new but equivalent field, and updates anything else using the Quote Number field in a concatenation function to use the new field.

That would be the best way, though it would require the most work. This is also the best way to accomplish what you need if you are using SugarCRM On Demand, rather than hosting it on your own server. And it is the only upgrade safe way to do this. There may already be a package out there that lets you do this, so you should probably check out SugarExchange.

Alternatively, you'd need to alter the Quotes database table vardefs, remove the unique constraint on the index quote_num, then reset the auto increment value of the database table to get it to start counting from whatever number you want.

To make this, albeit unrecommended (as it breaks compatibility with future SugarCRM updates and may have unintended side effects for anything that relies on this specific behavior of the Quote Number field), modification, follow the below steps.

This assumes you are hosting your instance of SugarCRM on your own server and not on SugarCRM On Demand, and that you are using MySQL. There are also several different ways of ultimately making the Quote Number resettable; this is just one of them - it may not be the best.

  1. Make a backup of your database and your SugarCRM instance. You should be doing these backups regularly no matter what, of course.

  2. Edit {SugarCRM root}/modules/Quotes/vardefs.php to remove the unique constraint on the quote_num index. You can find this in the indices element of the $dictionary['Quote'] array, toward the bottom of the file.

    Before:

    array('name' =>'quote_num', 'type'=>'unique', 'fields'=>array('quote_num', 'system_id'))

    After:

    array('name' =>'quote_num', 'type'=>'index', 'fields'=>array('quote_num', 'system_id'))

  3. Execute a Quick Repair and Rebuild. You do this by going to the SugarCRM Admin page, clicking on Repair, then Quick Repair and Rebuild. Once the first pass is over, you will see a text box at the bottom of the page with an SQL statement or two in it. Clicking on the "Execute" button will apply the updates you made to the Quotes vardefs index entry.

  4. Reset the quotes table's auto increment value. If your database is MySQL, you can do this by executing: ALTER TABLE quotes AUTO_INCREMENT=1 (if you want to start counting at 1 going forward).

Once those steps are complete, your Quote numbers will then start from 1 again (or whatever number you specified in your ALTER TABLE statement), and you will be able to reset the number again in the future by re-executing the ALTER TABLE statement.

Kyle Lowry
  • 1,246
  • 10
  • 14
  • could you please if you have some time to check and this one? http://stackoverflow.com/questions/15254673/sugarcrm-how-to-get-popup-when-click-on-save-button I want to get some pop up when clicking Save (first with some message later I would like to add OK and Cancel options). Thank you in advance – Stefke Mar 06 '13 at 18:07