These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Using variables to generate WO number

sdbrenner
Registered: Dec 4 2009
Posts: 9
Answered

I am trying to create a a form for Work Orders that will be able to generate it's own sequential work order number. I have zero Java experience, so I am really fumbling in the dark with everything that I've done.

I have a text field set up for the WO number, and I have created a button that, when pressed, clears the form, adds 1 to a variable that I've created, set sthe text field to that variable, and saves it as a new file:

Quote:

[b]xfa.host.resetData()
WOnum=WOnum+1
WO.rawValue=WOnum
app.execMenuItem("SaveAs")[/b]

So far, this is working. The problem that I run into is that once I enter data and save the form, if I reopen it, it resets the variable WOnum back to 0 - It doesn't save the value of the variable after the program closes.

At first I realized that part of the problem was my variable definition. I had the code to define the variable as:

Quote:

[b]var WOnum = 0[/b]

in a docReady event. This was resetting the variable to zero each time the document was reopened. I tried to change the code to something that would check for a variable value, and if there wasn't one (ie, it hadn't been created), it would define it and set it to zero:

Quote:

[b]if(WOnum){}
else{var WOnum=0}
[/b]

I don't know if what I've written is actually doing what I thought though. Obviously, it's not working as intended, but I don't know if it's this piece of code, or some other issue. Does the program automatically reset a variable after it closes?

I would really appreciate any help in getting the field to retain it's value after the program is closed and reopens.

sdbrenner
Registered: Dec 4 2009
Posts: 9
Okay, I have partially resovled my issue. Rather than setting the field 'WO' to a variable and having to deal with that, I'm just directly editing the field.

Quote:
xfa.host.resetData();
WO.rawValue++;
app.execMenuItem("SaveAs");
The issue I'm running into instead, is that the resetData() command is resetting that field as well. I know I can set it to only reset certain fields, but rather than have to include every single field other than that one inside this command, is it possible to just include the single field as an exception somehow?
sdbrenner
Registered: Dec 4 2009
Posts: 9
I think that I've finally solved the issue on my own. In case anyone has similar problems, this is what I ended up doing:

Quote:
[b]
var WOnum=WO.rawValue;
xfa.host.resetData();
WO.rawValue=WOnum+1;
app.execMenuItem("SaveAs");
[/b]