These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

getDate for a user entered date

woodwardian
Registered: May 25 2009
Posts: 8
Answered

Livecycle Javascript

Non-profit housing company with a situation where if someone exits after the 5th day of the month we collect the full rent from the subsidy (SubsidyDD field name) (Section 8 or a program called Shelter Plus Care) for the entire month. The end user will enter the move-out date (ExitDate) and the type of subsidy (we have about 10) and I need the form to check that date to see if it is >= 5 and that the subsidy is one of the two above. If these conditions are met then the field should equal the last day of the month, if not the field should be the actual ExitDate.
getDate does not seem to give me anything and I'm sure I am using it wrong.

Basic outline for the issue is this-

if ( (ExitDate.getDate() >= 5) && (( SubsidyDD == "Section 8") || (SubsidyDD == "Shelter Plus Care SRA"))); {
ExitDate.getMonth() + ('-') +
{if ((ExitDate.getMonth() == 0) || (ExitDate.getMonth() == 2) || (ExitDate.getMonth() == 4) || (ExitDate.getMonth() == 6) || (ExitDate.getMonth() == 7) || (ExitDate.getMonth() == 9) || (ExitDate.getMonth() == 11) ); {
31 } else if { ( (ExitDate.getMonth() == 3) || (ExitDate.getMonth() == 5) || (ExitDate.getMonth() == 8) || (ExitDate.getMonth() == 10) )}; {
30 } else { 28 }} + ('-') +
ExitDate.getYear();
} else {
ExitDate; }

any help or advice greatly appreciated

try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
You should not put semi-colons at the end of an if condition.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
It appears you are trying to mix JavaScript and FormCalc. It is best for a beginner not to try to mix the 2 languages.

There are some basic coding errors. The 'if' statement does not have a semicolon after the condition statement, if is either a line of code or a block of code. The semicolon at the end of the condition statement creates a null statement add the following block of code is always run.

It does not appear you have provided all the code that is being executed. Since you are using the 'getDate()' method of the JavaScript date time object of the date time object variable 'ExitDate'. Is 'ExitDate' even initialized?

Are you getting any errors when you enter or test this code?

Are you getting any erorrs when previewing this code?

You might try simplifying the code or adding some additional code to disclose how your script is working. you might consider adding code to display the values of fields that you are trying to manipulate before the manipulation and after.

Some starting JavaScript

// open and clear JavaScript Consoleconsole.show();console.clear();// wait until we have dataif(ExitDate.formatteValue != ""  & SubsidyDD.formattedValue != "") {// show some data objects on consoleconsole.println("ExitDate: " + ExitDate + " SubsidyDD: " + SubsidyDD);// show some data values on consoleconsole.println("ExitDate: " + ExitDate.formattedValue + " SubsidyDD: " + SubsidyDD.rawValue);// fill in a text field with the data values$.value = "ExitDate: " + ExitDate.formattedValue + " SubsidyDD: " + SubsidyDD.formattedValue;// convert ExitDate to date time objectvar oExitDate = util.scand("MM/DD/YYYY", ExitDate.formattedValue);// display the date time objectconsole.println("oExitDate: " + oExitDate);// extract the date from the date time objectconsole.println("Date: " + oExitDate.getDate());console.println("Month: " + oExitDate.getMonth());} // comment out problem code/*if ( (ExitDate.getDate() >= 5) && (( SubsidyDD == "Section 8") || (SubsidyDD == "Shelter Plus Care SRA"))); {ExitDate.getMonth() + ('-') +{if ((ExitDate.getMonth() ==  0) || (ExitDate.getMonth() ==  2) || (ExitDate.getMonth() ==  4) || (ExitDate.getMonth() ==  6) || (ExitDate.getMonth() ==  7) || (ExitDate.getMonth() ==  9) || (ExitDate.getMonth() ==  11) ); {31 } else if { ( (ExitDate.getMonth() ==  3) || (ExitDate.getMonth() ==  5) || (ExitDate.getMonth() ==  8) || (ExitDate.getMonth() ==  10) )}; {30 } else { 28 }} +  ('-') +ExitDate.getYear();} else {ExitDate; }*/

George Kaiser

woodwardian
Registered: May 25 2009
Posts: 8
Thanks for the advice.

I will try it later today.

Yeah, I really just need to stick with formcalc. So far it has been able to handle everything I would need.

I just need to check if the ExitDate it greater than the 5th in a invisible field using javascript and then work with formcalc from there.

It seems like this should be really simple, but it is fast becoming quite gnarly.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
If you are going to use FormCalc, then you need to use the "Date2Num()" funciton and then the "Num2Date()'" fucntion specifying the format for the date of the month, month, etc.

var sExitDate = ExitDate.formattedValue// have to match the format string to the format for the fieldvar fExitDate = Date2Num(ExitDate.formattedValue, "MM/DD/YYYY")var dExitDate = Num2Date(fExitDate, "D")var mExitDate = Num2Date(fExitDate, "M")xfa.host.messageBox(Concat("Exit Date: ", sExitDate, " SubsidyDD: ", SubsidyDD) )xfa.host.messageBox(Concat("ExitDate of month: ", dExitDate, " ExitDate month: ", mExitDate) )Concat(dExitDate, " ", SubsidyDD)elsenullendif

George Kaiser

woodwardian
Registered: May 25 2009
Posts: 8
Thank you,

That was so much simpler.
I was close on one of my original attempts, just missing a couple of bits of knowledge.
If our needs increase, I guess it will be time to take a course.

thanks again.