Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Show today's date + 10 days or show the event date if it is sooner.

New Here ,
May 06, 2016 May 06, 2016

I am creating a PDF agreement form.

I would like to have the deposit due 10 days from "Today's date" or On the "EventDate" whichever comes first.

currently it shows today's date + 10 days but sometimes the event date is sooner than that.

Thank you all in advance!

TOPICS
Acrobat SDK and JavaScript , Windows
644
Translate
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

correct answers 1 Correct answer

LEGEND , May 06, 2016 May 06, 2016

This script can be used for the deposit date:

// document level scripts;
function GetField(oDoc, cName)
{
// get field object with error checking;
oField = oDoc.getField(cName);
if(oField == null)
{
  app.alert("Error accessing field named " + cName + "\nPlease check field name spelling and capitalization.", 1, 0);
}
return oField;
} // end GetField function;

function Scand(cFormat, cDate)
{
// convert date stirng to date object with error checking;
var oDate = util.scand(cFormat, cDate);
if(oDate == n

...
Translate
New Here ,
May 06, 2016 May 06, 2016

This is what i tried... doesn't work though

var Today = new Date() ;

this.getField("Today").value = util.printd("mm/dd/yy", Today) ;

this.getField("dueDate").value = util.printd("mm/dd/yy", new Date(Today.getFullYear(),Today.getMonth(),Today.getDate()+10)) ;

if (dueDate.value) >= ("eventDate");

    this.getField("eventDate").value = util.printd("mm/dd/yy", dueDate) ;

Translate
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
LEGEND ,
May 06, 2016 May 06, 2016

Date string values like "01/01/2016" do not compare very well because of how string values are compared. If you were to create the string date values using the ISO date standard or YYMMDD you might have better success. I have found the best approach is to convert the date string to the JavaScript date object and then either use the value property of the date object or the getTime() method of the date object. Both provide the date and time value as the milliseconds since the Epoch date of January 1, 1970.

Translate
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 ,
May 06, 2016 May 06, 2016

I appreciate the help, i do not have any idea how to do that. the javascript i am using i found online.

Translate
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
LEGEND ,
May 06, 2016 May 06, 2016

This script can be used for the deposit date:

// document level scripts;
function GetField(oDoc, cName)
{
// get field object with error checking;
oField = oDoc.getField(cName);
if(oField == null)
{
  app.alert("Error accessing field named " + cName + "\nPlease check field name spelling and capitalization.", 1, 0);
}
return oField;
} // end GetField function;

function Scand(cFormat, cDate)
{
// convert date stirng to date object with error checking;
var oDate = util.scand(cFormat, cDate);
if(oDate == null)
{
  app.alert("Error converting date " + cDate + " using the format " + cFormat + "\nPlease check that the date is valid", 1, 0);
}
return oDate;
} // end Scand function;

function Date2Num(oDate)
{
// convert date object to number of days since epo// ch date;
// set time to midnight of date;
oDate.setHours(0, 0, 0, 0);
// convert milliseconds to days;
return Math.ceil(oDate.getTime() / (1000 * 60 * 60 * 24));
} // end Date2Num function;

function Num2Date(nDays)
{
// convert number of days to date object;
return oDate = new Date(nDays * 1000 * 60 * 60 *24);
} // end Num2Date funciton;

function SetDate()
{
if(GetField(this, "Today").valuesAsString == null || GetField(this, "Today").valuesAsString == "")
{
  var oToday = new Date(); // get system date;
  oToday.setHours(0, 0, 0, 0); //set to midnight;
  GetField(this, "Today").value = util.printd("dd-mmm-yyyy", oToday);
}
return;
}
// set today's date field;
SetDate();
// end document level scripts;

event.value = ""; // clear field;
// get field objects and field values;
var cToday = GetField(this, "Today").valueAsString;
var cEvent = GetField(this, "Event").valueAsString;
var cDateFormat = "dd-mmm-yyyy";
if(cToday != "" && cEvent != "")
{
// convertdate objects to days;
var oTodayDays = Scand(cDateFormat, cToday)
var nTodayDays = Date2Num(oTodayDays);
var oEventDays = Scand(cDateFormat, cEvent);
var nEventDays = Date2Num(oEventDays);
// make sure event date is not before today's date;
if(nEventDays < nTodayDays)
{
  app.alert("event date cannot be before today's date.", 1, 0);
}
else
{
  // assume deposit date is todays date + 10 days
  var nDepositDays = nTodayDays + 10
  if(nEventDays < nDepositDays)
  {
   nDepositDays = nEventDays;
  }
  // set deposit date;
  event.value = util.printd("dd-mmm-yyyy",  Num2Date(nDepositDays));
  }
}

Translate
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 ,
May 06, 2016 May 06, 2016

THANK YOU! i know that took a lot and maybe i shouldn't be attempting to do this on my own.

i do not know where to put that script and what fields to create other than "Event" and "Today"

Translate
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 ,
May 06, 2016 May 06, 2016
LATEST

Actually i got it to work... I just needed to create a third field names "nDepositDays"

THANK YOU

Translate
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