4 Replies Latest reply on Feb 24, 2016 1:46 PM by Me@UML

    Is there someone out there than can help with javascript in a fillable form in acrobat?

    Me@UML

      Hi,

      I have created a fillable form for time off, however there are fields for days with a from and to date with a pull down calendar (free download from formrouter.com) and fields with hours from and to.  There is a final field within each to total the time off requested, however I do not know how to create that calculation as our days are 7.5 and if there is only 1 day requested, but only a few hours then it wouldn't be 7.5.  There are a lot of "ifs" and I am not a programmer and don't understand the javascript.  If anyone out there knows this stuff and can give me a few minutes to show me how to complete this request form I would be grateful.  Thank you in advance.

        • 1. Re: Is there someone out there than can help with javascript in a fillable form in acrobat?
          gkaiseril MVP & Adobe Community Professional

          Check the calendar for August 31. Do you see any error?

           

          I would look at allowing form more than 1 day.

           

          To deal with the time portion of the JavaScript date object, one needs to specify the date.

           

          Have you tired to add the 7.5 hours to the date object for the start of the time off?

           

          The date time object will advance the years, months, days, hours, etc to the correct value when the adjustment added to it is larger then the unit being changed.

          • 2. Re: Is there someone out there than can help with javascript in a fillable form in acrobat?
            Me@UML Level 1

            Hi,

            I checked the date on 8/31 and I did not see an error.  I am not familiar with javascript at all.  I have asked the IT department to assist and haven't had a response that is why I have reach out to the adobe community.  Any assistance you can provide is appreciated.

            Thank you.

            • 3. Re: Is there someone out there than can help with javascript in a fillable form in acrobat?
              gkaiseril MVP & Adobe Community Professional

              I have downloaded the calendar picker from FormRouter and see that the August 31 missing date has been fixe.

               

              You script will require custom JavaScript coding and that means knowing each field name and format so that information can be used in the script to get each needed field object and the values of the objects as needed.

               

              The basic steps are to get the form field objects and then the values of the fields.

               

              To get the date object to modify one needs to convert the data string concatenated with the time string into a date object using the util.scand() method.

              Now one needs to get the number of hours for the time off and convert value into the parts of hours and minutes.

              Now one can adjust the date object's hours by the number of hours and the minutes by the number of minutes.

              The date object will now have the start time adjusted by requested number of hours.

              You can use the util.printd method to format the adjusted date object into a formatted date and time string.

               

              This is not a beginners task.

               

              Sample code:

               

              function GetField(oDoc, cName) {
              // get field object with error checking;
              var oField = oDoc.getField(cName);
              if(oField == null) {
              app.alert("Invalid field name: " + cName, 1, 0);
              }
              return oField;
              } // end GetField fucntion;

              function Scand(cFormat, cValue) {
              // convert date time string into date object with error checking;
              var oDate = util.scand(cFormat, cValue);
              if(oDate == null) {
              app.alert("Error in converting date string " + cValue + " with format " + cFormat + " into a date object", 1, 0);
              }
              return oDate;
              } // end Scand funciton;

              var cStartDate = "02/29/2016";
              var cStartTime = "11:30 pm";
              var cTimeOff = "7:30";
              // get the start date and time field objects values; // used if getting field value;
              // var cStartDate = = GetField(this, "StartDate").value; // used if getting fiel value;
              // var cStartTme = GetField(this, "StartTime").value;
              var cStartDate = "02/29/2016"; // force to string variable;
              var cStartTime = "11:30 pm"; // force to string variable;
              // create date time object for input values;
              var oDate = Scand("mm/dd/yyyy h:MMtt", cStartDate + " " + cStartTime);
              // get requested time off value;
              // code to get field value and convert the value to hours and decimal hours;
              var cTimeOff = 7.5; // force to numeric value;
              // adjust date object for requested time off value;
              oDate.setHours(oDate.getHours() + cTimeOff);
              // report ending value for time off;
              var cEndTimeOff = util.printd("m/d/yyyy h:MM tt", oDate);
              app.alert("Time off ends: " + cEndTimeOff, 3, 0);

              • 4. Re: Is there someone out there than can help with javascript in a fillable form in acrobat?
                Me@UML Level 1

                Would you be willing to discuss this off-line over a web meeting where I can share the form with you so you can see what I am talking about?