Copy link to clipboard
Copied
I'm trying to extract elements of the date on a signature and convert them into a string. I can extract the date/time element from a digital signature, but I can't seem to then convert that to a string.
The following script is run when the document is signed:
var f = this.getField("Signature1");
var Info = f.signatureInfo();
var d = Info.date; this.getField("Text1").value = d; //Works fine up to this point
var z = d.valueAsString;
this.getField("Text2").value = Left(z,5)
I have even tried replacing the last line with this.getField("Text2").value = z and get nothing?
Any assistance would be greatly appreciated.
The text box returns no value
Copy link to clipboard
Copied
Why do you use valueAsString? And why do you say you want to convert it to a string? Surely it's already a string? What value does it have?
Copy link to clipboard
Copied
I think my problem may have been answered in the next post. If there is no Mid, Left or Right in JS then that would explain it, although why I didn't get an error is a bit puzzling.
Copy link to clipboard
Copied
I am running the script when the document is signed. Would that matter?
Frustratingly, I solved the problem and managed to write the information I extracted to another text box using substring. I then tried to do all the calculations without using the first text box and now I can't remember what I did originally.
This script is run when the document is signed:
var f = this.getField("Signature1");
var Info = f.signatureInfo();
var d = Info.date;
this.getField("Text1").value = d;
No problem to this point and from there I calculate the next field using the script
var r = this.getField("Text1").substring(11,24);
this.getField("Text2").value = r
Nothing comes up in the second text box. I'm guessing it is my syntax when defining 'r'.
Copy link to clipboard
Copied
You're missing something important here:
var r = this.getField("Text1").substring(11,24);
You need to access the field's value...
Copy link to clipboard
Copied
You shouldn't have to guess. There should be an error message. Do you have the console open to check for them? Nothing will pop up if your code is wrong.
Copy link to clipboard
Copied
Thanks for your help - I managed to get it working. I'm not sure how to open the console? I am writing the script using Adobe Acrobat and placing it in the fields in the form.
Copy link to clipboard
Copied
Ctrl+J will open it. You should also enable the option to show it automatically when there are errors. This setting can be found under Edit - Preferences - JavaScript.
Under what event did you place the code, exactly?
Copy link to clipboard
Copied
There's no function in JS called Left. Did you define one yourself?
Copy link to clipboard
Copied
That would explain it. I am new to JS and assume there are Left, Right and Mid functions. Thanks for that.
Copy link to clipboard
Copied
It would have. Something like this:
ReferenceError: Left is not defined
[Edit: this was meant as a reply to your other reply, about not getting an error message...]