Gossamer Forum
Home : Products : DBMan : Customization :

Auto advance by one

Quote Reply
Auto advance by one
Hello, Iím trying to make my "Job Ticket" field advance by one number with each job.

I tried using this code and had no luck. Any ideal?

Under html_add_form

I add this:
------------------------------
<SCRIPT LANGUAGE="JavaScript">
function doCount() {
form.Job_Number.value = (form.ID.value + 5000);
}
</SCRIPT>

And modify this:
------------------------------
<body onLoad="doCount();>
<form action="$db_script_url" method="POST" name="form">


And under html_record_form

I add this:
------------------------------
<td width="31%"><INPUT TYPE="TEXT" NAME="Job_Number" SIZE="8" VALUE="$rec{'Job_Number'}" MAXLENGTH="8" tabindex="1"></td>

Thank you,
Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
If you set that field as the key field, you can use the $db_key_track feature and it will be taken care of for you.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Hello JPDeni, thank you for responding,

I tried this before, the problems I ran into was,

1) my job tickets start with #5000.

2) when I use the db_key tracking it starts with 1. Plus if I delete a record (say record number 5) the next time I add a new record, db_key will assign that record the next number inline (number 5).

Thank you,
Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
Quote:

1) my job tickets start with #5000.

2) when I use the db_key tracking it starts with 1.

Edit the default.count file. Put "5000" in there. It's just a text file. You can start with whatever you want.

Quote:

Plus if I delete a record (say record number 5) the next time I add a new record, db_key will assign that record the next number inline (number 5).

Whether you delete a record or not, the db_key will assign the next number in line.

Here's how the script works. If you have $db_key_track set, when you go to add a new record, the script opens the default.count file, sees what number is there and adds 1 to it. Then it sticks that value into the key field on the add form. When you click the submit button on the add form, first the file checks to see if that number already exists. If it does, then it adds one to it and checks again. It'll go through this up to 50 times before it gives up. Once the script is sure that the number doesn't already exist in the database, it adds the record and then puts the db_key value into the default.count file, overwriting what was already there.

When a record is deleted, it doesn't change the default.count file. If you delete record #5, there just will be no record #5. Seems to me that's what you would want.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Hello JP,

If this is the case, Then I think I have a problem with my db_key tracker.

Below is a copy of the 1st. 3 fields in my data base, the 1st field is my 'ID' (please note the first record is blank).
the 2nd field is my 'job number' (manually entered), 3rd field is a date field (auto enter). In this data base I deleted record number '5'. Than I added 2 more records to the data base. As you can see 'ID' became number 5 with the 1st enter and number 10 with the next.


1st. data base.

|5016|05-Nov-2006|
1|5001|29-Oct-2006|
2|5002|29-Oct-2006|
3|5003|29-Oct-2006|
4|5005|29-Oct-2006|
6|5015|30-Oct-2006|
7|5018|29-Oct-2006|
8|5019|04-Nov-2006|
9|5020|05-Nov-2006|


2nd data base.

|5016|05-Nov-2006|
1|5001|29-Oct-2006|
2|5002|29-Oct-2006|
3|5003|29-Oct-2006|
4|5005|29-Oct-2006|
6|5015|30-Oct-2006|
7|5018|29-Oct-2006|
8|5019|04-Nov-2006|
9|5020|05-Nov-2006|
5|5021|05-Nov-2006|
10|5022|05-Nov-2006|



I than started with a new data base, and set my 'default.count' to 5000. When I added my first record, the 'ID' was blank, and the 2nd record was set to '1'. I re-checked the 'default.count' and it too was set back to "1".


Any ideas?

Thank you,
Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
What is the date? Is that when the record was added?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Yes it is.

Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
I don't know what's going on here, to tell you the truth. Are you sure you have the field named correctly in your sub html_record_form? It has to match the name from the .cfg file exactly, including letter case. That's the only thing I can think of that would cause this.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Yes They are, I just check them and they are the same.

Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
The only thing I can suggest is that you attach your default.cfg file and your html.pl file to a post. I'll download them and take a look. Something is definitely wrong.

It is a whole lot better if you attach them, rather than posting the text to a message. It's easier for me to read that way. :)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Thank you,
I'll that.

Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
Actually, something else occurred to me. Check in your default.cfg file and make sure that you have

$db_key_track = 1;

and that your $db_key value is pointing to the right field -- spelling counts! ;-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [knue] Auto advance by one In reply to
Hello JPD,

Here they are.

Thank you,
Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
I see the problem.

You have a separate form in sub html_add_form, which is perfectly okay, but you left out an important part of it. The original code has the line

&html_record_form (&get_defaults);

The &get_defaults part is what accesses the default.count file in the first place. That would account for your problems.

Another thing that would account for them is that you have no ID field in that add form. You have it in sub html_record_form, but not in the form you're actually using to add a record.

You need to do two things. First, instead of

$rec{'Date'} = &get_date();

use

%rec = &get_defaults;

That will fetch both the date and the record number, plus any other things you might want to prefill into your form.

Second, somewhere in your html_add_form, you need to add

<INPUT type="hidden" NAME="ID" VALUE="$rec{'ID'}">

(Also, if you ever use sub html_record_form, you need to fix the way the field is structured. There's a little problem with your html there.)

With those two things, the numbering should work just fine.




JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Auto advance by one In reply to
Hello JPD,

Thank you, That did the trick. and it fix other problems I had and some I didn't know I had.

In order to get my "sub html_add_form" to work correctly, I need to remove my html code and replace it with the original code. But this turned out to be a good thing for the other problems I had.

Thank you again for your help.Smile

Ed
Quote Reply
Re: [knue] Auto advance by one In reply to
You're very welcome. Sometimes the answers to problems don't seem to be clear. Another set of eyes is often all that's needed.

Best of luck on your project.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.