Expand my Community achievements bar.

SOLVED

Trouble checking date field value with formcalc

Avatar

Level 2

Hi, my appologies if this has been asked. I found a few threads in searching the forums that deal with similar issues, but the solutions didn't help me any so I decided to start a new discussion.

I have a field called date1 and I have a field called rate. Quite simply, all I want to do is determine the default value held in rate based on whether date1 is set prior to 7/1/2011.

Here is what I have tried with no luck.

if (Date2Num(form1.#subform[0].Table1.Row2.date1.formattedValue, "M/D/YYYY") >= "07/01/2011")then

form1.#subform[0].Table1.Row2.rate1.rawValue = .555

else

form1.#subform[0].Table1.Row2.rate1.rawValue = .51

endif

I have also tried several other bits of code, including some java script with no luck. I would have to assume my error is somewhere in the way the field 'compares' the datefield with the value I specify in the formula.

I am a total form newb so I appologize if this comes off a bit ignorant.


Thanks for any help I receive, in advance.


C. S.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The Date2NUm function will return you the number of seconds that have elapsed since the epoch so you will need to compare it to the number of seconds that have elapsed from the epoch for 07/01/2011 ....so

if (Date2Num(form1.#subform[0].Table1.Row2.date1.formattedValue, "MM/DD/YYYY") >= Date2Num("07/01/2011", "MM/DD/YYYY))then

Paul

View solution in original post

10 Replies

Avatar

Level 10

Since you are checking the format for 07/01/2011, try changing the format in the function.

if (Date2Num(form1.#subform[0].Table1.Row2.date1.formattedValue, "MM/DD/YYYY") >= "07/01/2011")then

form1.#subform[0].Table1.Row2.rate1.rawValue = .555

else

form1.#subform[0].Table1.Row2.rate1.rawValue = .51

endif

Thanks

Srini

Avatar

Correct answer by
Former Community Member

The Date2NUm function will return you the number of seconds that have elapsed since the epoch so you will need to compare it to the number of seconds that have elapsed from the epoch for 07/01/2011 ....so

if (Date2Num(form1.#subform[0].Table1.Row2.date1.formattedValue, "MM/DD/YYYY") >= Date2Num("07/01/2011", "MM/DD/YYYY))then

Paul

Avatar

Level 2

Well, niether of those options seemed to work. I am not getting an script errors with it, but it fails to change the field if I change the date. Here is what I have currently.

if (Date2Num(form1.#subform[0].Table1.Row2.date1.formattedValue, "MM/DD/YYYY") >= Date2Num("07/01/2011", "MM/DD/YYYY"))then

form1.#subform[0].Table1.Row2.rate1.rawValue = .555

else

form1.#subform[0].Table1.Row2.rate1.rawValue = .51 endif

Thanks for the help!

Any other suggestions?

Avatar

Level 10

Syntax seems tobe correct. Can you share your form to have a look at it..

Thanks

Srini

Avatar

Level 2

I'll have to find someplace to host it, I am not familiar with 'sharing' forms other than through webhosting. Let me find someplace I can upload it and then I will post a link.

Thanks!

Avatar

Level 10

Steps to share a document..

1. Go to URL http://Acrobat.com
2. Create an account if you don't have one.
3. Then login to the website.
4. In top left corner you will see a button called Upload.
5. Click on browse and select the file you want to upload.
6. After Uploading, mouse over on the uploaded file. Click the down arrow button and choose Share document.
7. Then you will be prompted a popup window at the lower left corner. Choose "Publish it" option.
8. In the next pop up window choose "Copy Link" option.
9. You can paste the link in the forum thread.

Thanks

Srini

Avatar

Level 2

Excellent instructions!!!

Here is is..

https://acrobat.com/#d=15D4Nz4q8Ce7zatQdgUPDQ

I have only started working the formula through on the first table row. It is far from finished layout wise as well. I just like to get the functionality working before making it "pretty".

Let me know what I did wrong if you see anything..

Thanks again!

Avatar

Former Community Member

There is nothing wrong with your code. You placed it on the Initialize event which means that it is only executed when the form starts up. Take the code out of that event and put it on the Calculate event. Now it will fire everytime a referenced field (from your calculation) changes.

Paul

Avatar

Level 2

*HEADSLAP*

thanks for opening my eyes.. I was about to go batty..

Thanks everyone for all the help!

Avatar

Level 10

Below is the working script..

if (Date2Num($.formattedValue, "M/D/YYYY") >= Date2Num("7/1/2011", "M/D/YYYY"))then

Table1.Row2.rate1.rawValue = .555

else

Table1.Row2.rate1.rawValue = .51

endif

You had placed the script in the Initialize event of the Mileage rate field. It is supposed to be in the Exit event of the Date field in the same row.

https://acrobat.com/#d=OufLQsJsnoBOoxy-JmDRiA

Thanks

Srini

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----