Auto Populate Date on Event and then Lock Date to Prevent Updating

New Here ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

I have a need for the following.

A date field (FieldA) needs to be auto populated on the current date when the signature field (SignA) is populated.  I wrote this code to accomplish this, and its placed in the Custom Calculation Script in the date field (FieldA).  It works.

event.value=(this.getField("SignA").valueAsString=="")?"":

util.printd("m/d/yyyy",new Date());

 

There are 4 different signatures requried on this field, hence all 4 will have the same requirement.

However, I did not take into account that the form will be signed on different days.  Once the first date is populated after the first signature, and a day(s) passes, when the form is modified, it recalcuates and updates the already populated dates to most current.  I want to lock the date once SignA is signed and FieldA is calculated for the first time, with no further updates to that date.  I hope this makes sense.

 

Thanks,

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, General troubleshooting, PDF forms

Views

98

Likes

translate

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
community guidelines
Adobe Community Professional ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

Are you trying to get the current date during signing time using digital certificate signature fields?

Likes

translate

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
community guidelines
New Here ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

Yes, it is for a digital certificate signature field. While I understand the date and time are stamped with the signature, like another poster indicated, this is for a government form, thus the redundancy......  I can either gather the date from the certificate information or not.  It just needs to be the date signature applied, and I'm tired of people missing it or entering the wrong date.

Likes

translate

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
community guidelines
Adobe Community Professional ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

I posted this for you in my last reply just in case you missed it: https://community.adobe.com/t5/acrobat/javascipt-to-abort-code-and-return-to-dialog-box/m-p/11244384...

 

This is what I am using in my forms:

 

 

var f = event.target;
    var sigInfo = f.signatureInfo();
    var date = util.printd("yyyymmdd", new Date());
    var cert = sigInfo.certificates[0];

    var firstName = cert.subjectDN.cn.split(".")[1];
    var lastName = cert.subjectDN.cn.split(".")[0];
    var middleName = cert.subjectDN.cn.split(".")[2];
    var dodNum = cert.subjectDN.cn.split("'.")[3];
    var c = middleName.charAt(0);
    var d = c.toUpperCase()+".";

var first = firstName.charAt(0).toUpperCase() + firstName.substring(1).toLowerCase();
var last = lastName.charAt(0).toUpperCase() + lastName.substring(1).toLowerCase();



if (f.valueAsString !=="") {
  

 if ((c == "1")|| (c == "2")||(c == "3")||(c == "4")||(c == "5")||(c == "6")||(c == "7")||(c == "8")||(c == "9")||(c == "0")){ 

 this.getField("Approver Name").value = first+" "+ last;
}

else if ((c !== "1")||(c !== "2")||(c !== "3")||(c !== "4")||(c !== "5")||(c !== "6")||(c !== "7")||(c !== "8")||(c !== "9")||(c !== "0")) {

this.getField("Approver Name").value =  first+" "+ d+" "+last;
  }
}

else f.value ="";

 

 

This script grabs the full name (first, middle , and last name) from the distinguished name of the digital certificate and outputs it as first name, middle initial (if found), and the last name (all names with the first letter to upper case).

 

This works for government forms where signatures are applied using CAC Cards. And I developed this script because me too fall under the category of a getting really tired of  government forms  users who doesn't pay attention to  details and also miss missed typing their full name and date when required, even if the signature field has been signed.

 

But to answer your question specifically, the lines of code that you  need should look like  this for a mouse up javascript action: 

 

 

var f = event.target;
    var sigInfo = f.signatureInfo();
    var date = util.printd("m/d/yyyy", new Date());
   
if (f.valueAsString !=="") {this.getField("myDateField").value = date;}

 

 

Then  you can add a custom calcultaion script in the date field like this :

 

if (this.getField("Signature1").value =="") event.value ="";

 

so it clears automatically when you clear the signature (you can also make your date field read-only)

 

If you noticed in the main script above I am using util.printd  with new Date() method. This is because if you grab the date from the signatureInfo() properties of the digital certificate it may output with unexpected results if the computer that the user is signing from has a different time zone (i. e. behind a VPNs, or different clocks set by the OS)  than that of the timezone offset provided by the time stamp server.

 

 

Likes

translate

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
community guidelines
Most Valuable Participant ,
Jul 02, 2020 Jul 02, 2020

Copy link to clipboard

Copied

Instead of using a calculation script use the first Signature's Signed event to populate the field, and then lock it.

However, a signature already contains the date and time it was applied, so this is not really necessary.

Likes

translate

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
community guidelines
Adobe Community Professional ,
Jul 02, 2020 Jul 02, 2020

Copy link to clipboard

Copied

It is necessary in  most (if not every) government forms though.

 

They require the signers to apply the digital signatre and also type in their full name  and select the current date.

 

If this is your case, please check out this thread: https://community.adobe.com/t5/acrobat/javascipt-to-abort-code-and-return-to-dialog-box/m-p/11244384... 

 

There is an example of a script that I am using as a workaround in

 government forms where a user must type name and date in addition to signing.

 

This script can be improved though.

 

kudos to Try67 who guided me on this a long while ago.

 

Likes

translate

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
community guidelines