6 Replies Latest reply on Nov 23, 2016 8:32 PM by dan_movie

    signatureInfo and send email message body

    dan_movie

      Hi All  (new to this forum and to javascript).

       

      I have created a form with 3 signature fields plus an email button.

      I am able to "populate" my email with proper info, etc.

      I have figured out the use of unicode to enter line breaks since with my acrobat 9 the outlook email message is by default plain text.

      (i don't know how to make it "open" with a new message in HTML format)

       

      Form is basically filled out and approved by one person then emailed upwards for 2nd approval then

      upwards again for a 3rd approval. Each email to the next "approver" is on a seperate button.

      (ie:  To BOB, To BILL, once all 3 signatures are in - To DISTRIBUTE)

       

      What I would like to do is add the name of the sender to my email message.

      I am thinking that the best way, is to get the name of the last person to sign the PDF.

      Assuming the last person to sign would have also hit the email button.

       

      I need some help in my triggers and coding to find out which of the 3 signature fields was last entered.

      I was thinking of using the OnFocus & Signed events to compare what is in the signature field.

      Blank on entry, signed on exit = last person to sign the form.

      For OnFocus:

      var f = this.getField("FirstApproval");

        var status = f.signatureValidate();

          // Check the status returned from the validation:

        if (status < 3){

        var msg1 = "not signed yet";}

        else{

        var msg1 = "already signed";}

       

      For Signed:

      var f = this.getField("FirstApproval");

      var sigInfo = f.signatureInfo();

       

      var Name1 = sigInfo.name;

       

      What I can't figure out is the scope of the variables,

      how do I pass the msg1 & Name1 content to my email button script ?

      So that this can be evaluated:

       

      If(msg1 == "not signed yet"){

      // add the name of the last person to sign at the end of the message body

          cMessBody = cMessBody + Name1;}

       

      Once that is sorted out, it should be some if or case statements to compare the info from all 3 signature fields

      so that i use the last signed one to insert into the email message body.

       

      Any simpler ideas to pass the user name to my email message is more than welcomed !

      Thanks

        • 1. Re: signatureInfo and send email message body
          try67 MVP & Adobe Community Professional

          You need to include all code in the same script, and also don't defined your variables (using the var keyword) inside an if-statement, because then they might only be available inside that scope. So instead of this:

           

          if (status < 3) {
          var msg1 = "not signed yet";}
          else {
          var msg1 = "already signed";}
          

           

          You should do this:

           

          var msg1;
          if (status < 3) {
          msg1 = "not signed yet";}
          else {
          msg1 = "already signed";}
          
          • 2. Re: signatureInfo and send email message body
            dan_movie Level 1

            thanks for the variable tip.

             

            If code needs to be all in same script, all I can think of, is comparing all 3 signature fields

            to see which ones are filled then comparing date stamps to find most recent signature.

            • 3. Re: signatureInfo and send email message body
              dan_movie Level 1

              Hi All,

               

              As mentioned by try67, since all code needed to be in one script, I decided to just compare timestamps of the signature fields. I came up with the code below which works well when at least one signature is present BUT generates an error at line 32 of code: var position = finalName.indexOf("<");

               

              Not sure what I am forgetting to test or what is missing - HELP please !

               

              var sign1 = this.getField("FirstApproval");
              var sign2 = this.getField("SecondApproval");
              var sign3 = this.getField("ThirdApproval");
              
              
              // compare valid signature timestamps
              var sigInfo1 = sign1.signatureInfo();
              var sigInfo2 = sign2.signatureInfo();
              var sigInfo3 = sign3.signatureInfo();
              var dt1 = sigInfo1.date;
              var dt2 = sigInfo2.date;
              var dt3 = sigInfo3.date;
              var finalName = "";
              var dateMath = "";
              
              
              if (dt1 < dt2){
                dateMath = dt2;
                finalName = sigInfo2.name;
              }
              else{
                dateMath = dt1;
                finalName = sigInfo1.name;
              }
              
              
              if (dateMath < dt3){
                finalName = sigInfo3.name;
              }
              
              
              var position = finalName.indexOf("<");
              if (position > 0){
                 finalName = finalName.substring(0,position);
              }
              else{
                 finalName = "";
              }
              
              • 4. Re: signatureInfo and send email message body
                try67 MVP & Adobe Community Professional

                What does the error message say, exactly?

                • 5. Re: signatureInfo and send email message body
                  dan_movie Level 1

                  TypeError: finalName is null

                  Field:Mouse Up

                  • 6. Re: signatureInfo and send email message body
                    dan_movie Level 1

                    Solved it !

                    In line 30 of the code in the post above i added...

                     

                    if (finalName == null){  
                        finalName = "sender";  
                    } 
                    

                     

                     

                    really could have been any text or space. it is really just to force a value in the field so it is no longer "null" if the form

                    has no signatures yet and the Email To button is pressed. The only character that should NOT be there is the "<" symbol

                    since I am looking for that in the substring expression to get the sender's name without the email address that is  < email > in the signatureInfo()

                     

                    D