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

Problem with a leading Zero is a string to number transformation

CaLeyCon
Registered: Oct 23 2011
Posts: 7

I am a completely green user of LiveCycle. I am trying to make a form for my husband to your for his small business. But I have a problem which I hope you could help me to solve. So what I am trying to achieve is to make a 5 digit code which will become a costumer number. The idea is to make it of the costumer company real name. I want to take the first 4 letter of the company name and convert them to a number. Plus add a leading 0 (zero) to it. I haven’t really made up my mind on what number each letter should represent but it is now what I need you to help me. So let’s say that the system is A,B,C=1 D,E,F=2 etc.
1: I made a drop-down list with the companies’ names.
2: I created a costumer number text field where the 5 digit code should appear.
3: I made a code in FormCalc and it is as follow:
OffertenGiltig.#subform[0].Header.KundNummer::calculate - (FormCalc, client)
KundNummer[0]=""
if (HasValue(Företagsnamn[0])) then
var Forkortning=Replace(Företagsnamn, " ", "")
Forkortning=Replace(Forkortning, "-", "")
Forkortning=Replace(Forkortning, ".", "")
Forkortning=Upper(Substr(Forkortning, 0, 4))
Forkortning=Replace(Forkortning, "A", "1")
Forkortning=Replace(Forkortning, "B", "1")
Forkortning=Replace(Forkortning, "C", "1")
Forkortning=Replace(Forkortning, "D", "2")

Forkortning=Replace(Forkortning, "Z", "8")
Forkortning=Concat("0", Forkortning)
endif
I know that there is surly a nicer way of making this could. But it actually works. The problem is that when the form is opened and as long as no company name is chosen in the drop-down window the value of the KundNummer is “0” which is an irritating detail. I would like it to be empty (NULL). I was hoping that the IF statement was doing the trick but NOT. Can you help me?
I am also open for all suggesting is how to make my code unique. In other words make sure that no company names get the same 5 digit combination.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The HasValue function does not seem to be working as expected.

Try this variation, without the instance id

if (HasValue(Företagsnamn)) then
... Same code ...
else
KundNummer =""
endif

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CaLeyCon
Registered: Oct 23 2011
Posts: 7
Hello Thom!

I haven't yet tested you suggestion. So I will check that later.
I want take this opportunity to ask you one other think. It has to do with a replay you did ones give in this forum related to a different problem, see http://acrobatusers.com/forum/forms-livecycle-designer/help-please-check-box-return-value-another-field.

I have the same situation, but I can't make your code work. Here is the code as I wrote it:

OffertenGiltig.#subform[0].Header.CheckBox1::mouseUp - (JavaScript, client)
if (this.rawValue)
{
LevFöretagsnamn.access = "readOnly";
LevFöretagsnamn.calculate.override = "error";
LevFöretagsnamn.value.setAttribute("0","override");
LevFöretagsnamn.execCalculate();
}
else
{
LevFöretagsnamn.access = "open";
LevFöretagsnamn.calculate.override = "disabled";
LevFöretagsnamn.value.setAttribute("1","override");
}


OffertenGiltig.#subform[0].Header.LevFöretagsnamn::initialize - (JavaScript, client)
this.calculate.override = "disabled";
this.value.setAttribute("1","override")

What I need is to get the text from KundNummer[1] to appear in the LevFöretagsnamn field when the CheckBox1 is marked. The problem I think is that KundNummer[1] is not referred in the code above. Can you help me on how and where that information show appear?
I should add that KundNummer[1] is a drop-down field. When I use the code as it is in the pdf you can see that the highlighted LevFöretagsnamn field becomes just white.

Waiting anxiously for you replay. Thanks!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What's missing is the calculation script. The code above turns calculations on and off for the "LevFöretagsnamn". The calculation in the same field is used to copy data from "KundNummer".

Here is the calculation script for "LevFöretagsnamn"

KundNummer.rawValue;

That's all you need. This one short line of code copies anything entered into the "KundNummer" field, Unless the calculation override is turned on.

I actually wrote an entire article on this topic at pdfscripting.com



BTW: Do you have two different fields named "KundNummer". If so then you should give them different names.




Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CaLeyCon
Registered: Oct 23 2011
Posts: 7
Hmmm!

Problem a: Is that I have 2 KundNummer fields. The reason for that I will mention later.

Problem b: In order to just make your code to work I have how instead chosen 2 other variabler: GatuAdress and LevGatuadress.
So the adress on field GatuAdress I want to apeare in the LevGatuAdress field when CheckBox1 is marked.
If I did understand you right so I added the following script to the calculation entry in the LevGatuadress.

OffertenGiltig.#subform[0].Header.LevGatuadress::calculate - (JavaScript, client)
Gatuadress.rawValue;

But it seems no matter if the CheckBox1 is marked or not. It always add the GatuAdress into the LevGatuadress field.
What am I doing wrong? and what did you mean with: "Unless the calculation override is turned on."
Sorry if my questions seem to stupid: I have been playing with this just for a week.
Thanks!


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is the Value "Type" on the "KundNummer" field set to "Calculated - User can override"? Very important.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CaLeyCon
Registered: Oct 23 2011
Posts: 7
Sorry Thom!

Still the code doesn't want to work properly. No matter if the CheckBox1 is marked or not. LevGatuadress gets always the value of Gatuadress. If I try to give LevGatuadress a different value it overwrites it to the value of Gatuadress.
The only think the CheckBox1 does it lock the LevGatuadress so that it can not be touched or overwritten.

Do you have a mailadress I could send you a sample? So you can look at the code.

2: The goal if to make totally of 4 associations to work on the same way with the help of the same CheckBox1. The idea was to avoid to write the same information twice in the same form. If the information is the same of course. In other case the fields I should be ably to add different information to the fields.

3: The issue with the KundNummer[1] is that there exist an other KundNummer[0] which it is connected to. They are 2 drop-down fields. Where the value of the one is related to the other one. I did it with a help of a pdf example I found on the net:
"Assure-Dynamics-Linked-dropdown-lists.pdf".

I hope you can still help me with this issue. Thanks ones again for you time.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please post your example to Acrobat.com. Although I have to say that this is getting a bit beyond casual forum help. Have you considered hiring a consultant?


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CaLeyCon
Registered: Oct 23 2011
Posts: 7
If I have done right the files URL is as follow:
https://acrobat.com/#d=uONpfE*eip*lo8CulMgViw

Of course if I will not succeed to do this right I have to options: a) To leave this problem behind b) get a consultant. But I will probably not learn anything about is myself, will I?
But of course I will understand if you are not willing/interested in help me with is issue.
Thanks!

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You have to understand that it takes a great deal of time and effort to analyze someone else's form.

Just to get us on the some page, the general concept you are trying to implement is this:
1. Address data is automatically copied from address field #1 into address field #2, unless the user has a manual entry check box turned on.

2. If the manual entry check box is turned on then the user can enter data into the address field #2 with no interference from the address field #1.

Part#1 is implemented with a calculation script in address field #2

Part#2 is implemented with a script in the check box that switches on the calculation override for address field #2, which blocks the calculation script from running.

The best strategy for approaching a solution is to start with a blank test form and implement the solution on a single pair of fields. Your original form may have scripts and/or features that are interfering with your current solution.

But, as I said earlier, I have and article that explains in detail how to use the calculation override at pdfscripting.com. This is much cheaper than hiring a consultant, and very informative.




Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

CaLeyCon
Registered: Oct 23 2011
Posts: 7
Sorry for my late replay!

I will sit down and follow you recommended above.
I will also take my time and visit the homepage you mention.
Thanks ones again for taking your time!
Best regards Leyla
CaLeyCon
Registered: Oct 23 2011
Posts: 7
Thomp I am writing to you ones again.
You were right! When I created a whole new form with the fields I need the script works just fine.
I just need to say, that I initially marked "Calculated - User can override" in the wrong filed. Actually you have above indicated to the wrong field. *Smiling*

In the form I created to begin with. I tried to delete the 3 involved fields, create them ones again and implement the script. Unfortunately the code is not working ones again. How to solve this problem is over my knowledge.
So I think I will have to redo my whole form and hope that it will work this time.

So ones again, you were right about your code working just fine!


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In scripting it is very important to get the names of things correct. When something doesn't work correctly, the names are one of the first things I look at. It also helps if you keep the names simple and compact, and have some kind of consistent scheme for naming things in your form and scripts.

Another possibility for the problem with your current form is that you may have added code in an earlier attempt to solve this issue that is now causing an issue.

I hope this helps. Recreating a form is very time consuming.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script