Date field populates with today's date when Signature signed via sigpad

Community Beginner ,
Oct 25, 2017

Copy link to clipboard

Copied

Hello,

I'm able to populate today's date to a single field by inserting this script to the Signature field.

this.getField("Datefield1").value = util.printd ("m/d/yyyy", new Date());

How can I do an "OR" to the above script so I can insert 5 fields? Reason being is the naming convention of the date field can be five different names.

Datefiled1

Datefiled2

Datefiled3

Datefiled4

Datefiled5

Instead of going into the script and edit the Datefield, I just want the script to work for any of the five.

I tired this but no luck....

this.getField(("Datefield1")||("Datefield2")).value = util.printd ("m/d/yyyy", new Date());

Thank you

Ed

TOPICS
Acrobat SDK and JavaScript

Views

154

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Date field populates with today's date when Signature signed via sigpad

Community Beginner ,
Oct 25, 2017

Copy link to clipboard

Copied

Hello,

I'm able to populate today's date to a single field by inserting this script to the Signature field.

this.getField("Datefield1").value = util.printd ("m/d/yyyy", new Date());

How can I do an "OR" to the above script so I can insert 5 fields? Reason being is the naming convention of the date field can be five different names.

Datefiled1

Datefiled2

Datefiled3

Datefiled4

Datefiled5

Instead of going into the script and edit the Datefield, I just want the script to work for any of the five.

I tired this but no luck....

this.getField(("Datefield1")||("Datefield2")).value = util.printd ("m/d/yyyy", new Date());

Thank you

Ed

TOPICS
Acrobat SDK and JavaScript

Views

155

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2017 0
Adobe Community Professional ,
Oct 25, 2017

Copy link to clipboard

Copied

The "||" is the logical OR operator and is used in logical expressions. You can not use it for a field name in the getField method. Logical expressions are statements the evaluate to either a logical value of true or false.  The logical OR statement is used to evaluate the result of two logical statements to one logical value. Following is the truth table for the logical OR.

OR    |  true  |  false |

-------+--------+--------+

true   |  true  }  true   |

-------+--------+--------+

false |  true  }  false  |

-------+--------+--------+

If either statement or both statements are true the result is true. The false value is only possible if both statements are false.

I would create a variable with the current date and then assign that variable's value to each date field.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2017 0
Community Beginner ,
Oct 25, 2017

Copy link to clipboard

Copied

Thanks for the reply gkaiseril

The problem I have with setting a variable with a current date is because the variable must be unique (up to five) depending on the content of the form. To clarify 'unique', these variables are going to be captured by vendor when the form is submitted via API interface. The vendor identifies if it's either Field1, Field2, Field3, etc and processes this form on their end.

Rather than constantly editing the script in the signature field, I'm hoping a script can be written in such a way that it responds on the condition that the date field are any of the five variables noted above. Hope this makes sense.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2017 0
Most Valuable Participant ,
Oct 25, 2017

Copy link to clipboard

Copied

Your condition is not very clear... Based on what do you want to decide which field to populate, exactly?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2017 0
Community Beginner ,
Oct 25, 2017

Copy link to clipboard

Copied

I inserted the script noted above to a signature field.

this.getField("Datefield1").value = util.printd ("m/d/yyyy", new Date());

When signing, today's date populates on the neghboring non-sig field called Datefield1. The issue im running into is that the variable name of the date field is not always Datefield1. It can also be Datefield2, Datefield3, Datefield4,Datefield5. Depending on the content of the form. Instead of repeatedly going into the signature field and edit the script, I was wondering if a script can be written that says, When the sig field is signed, populate today's date on the date field where the date field can be any of the five variables.

Sorry, I hope this is a bit more clear.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2017 0
try67 LATEST
Most Valuable Participant ,
Oct 25, 2017

Copy link to clipboard

Copied

A weird set-up, but I understand what you mean now. You can use this code:

for (var i=1; i<=5; i++) {

    var f = this.getField("Datefield"+i);

    if (f!=null) f.value = util.printd ("m/d/yyyy", new Date());  

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2017 0