Expand my Community achievements bar.

Date specific to calculate late fee

Avatar

Former Community Member
I am trying to make the form calculate and automatic late fee. I am sure I need to use the if then format, but I can't find what format to use to check the late fee date.



The formula needs to do this.

If todays date is <= April 1, 2006 then

latefee=0

else

late fee is $30.00



I know that isn't all the correct formula, it is the date format I can not find. Can anyone help?

Thanks
20 Replies

Avatar

Former Community Member
Here's a script (in JavaScript) that compares today's date with "April 1, 2006" and shows a message box that says "on time!" if today is on or earlier than April 1st and "overdue!" if it's past April 1st:






var oToday = new Date();



if (oToday > new Date("4/1/2006"))

app.alert("overdue!");

else

app.alert("on time!");






Stefan C.

Adobe Systems

Avatar

Former Community Member
Thank you...I will see if I can incorporate that now.

Thank you very much!

Avatar

Former Community Member
I put this in calculate.

What am I doing wrong?



var oToday = new Date();

if (oToday > new Date("3/1/2006")) then

this.rawValue = 30.00;



else

latefee.rawValue =.00;



endif

Avatar

Former Community Member
Did you put this in the Calculate event of the
latefee field? I'm asking because when there's a late fee, you're executing the code "this.rawValue = 30.00" which will set the value of the field on which the Calculate event is executing whereas when there's no late fee, you're executing "latefee.rawValue = .00" which will set the value of the latefee field explicitely.



If you put this code on any other field than latefee, you'll probably see some wired behaviour like the latefee field's value never getting set when there should be a late fee.



Stefan C.

Adobe Systems

Avatar

Former Community Member
Also (just thought of this possibility), make sure you've set the script's
language property, in the Script Editor (top right-hand corner drop down list) to
JavaScript or else you'll get a scripting error and your script won't execute. The default language is FormCalc but the script you're using won't work in FormCalc.



Stefan C.

Adobe Systems

Avatar

Former Community Member
Yes, I put it in the Calculate field and made sure it was switched to Javascript.

I corrected my script so it read this.rawValue in both place.

Yes, It is in the "latefee" button Calc.

but this is not working.



I tried placing latefee.rawValue in both places and that didn't work either.



Any other suggestions?

thanks

Avatar

Former Community Member
I'm sorry. I should've noticed this earlier: The problem must be the
then keyword in your IF statement. It's not valid JavaScript.



On a form, I placed a numeric field which I named
latefee. Then I specified script (with language set to
JavaScript) for its
calculate event as follows:



var oToday = new Date();



if (oToday > new Date("4/1/2006"))

this.rawValue = 30.00;

else

this.rawValue = .00;


When I preview the form, the latefee field is populated with "0" because we aren't past April 1st yet.



The
then keyword is part of the FormCalc language (it's also used in Visual Basic and VBScript). In JavaScript (which is like Java), there's no
then. If you have more than a single statement to do in the IF and/or the ELSE clause, you enclose them in braces as follows:



if (oToday > new Date("4/1/2006"))

{

this.rawValue = 30.00;



// notify client that a late fee is applied

app.alert("Unfortunately, a late fee must be applied as today is past the due date of April 1, 2006.");

}

else

this.rawValue = .00;


I hope this fixes the problem.



Stefan C.

Adobe Systems

Avatar

Former Community Member
I thought you might also like to set the latefee field's
value type to
Calculated - Read Only to prevent someone filling-out your form to change the field's value back to zero.



By default, calculated values in fields can be overriden simply by typing-in a different number (so when we're past April 1st, someone could easily just replace the "30.00" in the field with "0.00").



By selecting the latefee field and going to the Value tab on the Object palette, you can change the field's type to
Calculated - Read Only. When you do so, two radio buttons will appear below, one with the title
Calculation Script. Make sure that this radio button is selected.



This will make your latefee field disabled (but still visible) on the form and its calculation will still run. Also, other fields like the total (assuming your form has a field which calculates the total cost of something) will still be able to get the latefee field's calculated value.



I hope this helps!



Stefan C.

Adobe Systems

Avatar

Former Community Member
Stefan,

I can't thank you enough. THANK YOU!

It works now. I changed the date to March 1st and it works perfect for both situations.



I wish I could discern when to use Javascript and when to use Formcalc. I have been reading tons of info, trying to educate myself.



I didn't realize programming these forms would be so tough, but they are SWEET when they are complete.



thanks again

Avatar

Former Community Member
You're welcome! I'm glad your form works now.



If I recall correctly, FormCalc was a language designed to resemble writing calculations in Excel (which are usually writeable on a single line) and geared towards typical form calculations. I believe you would typically use FormCalc when writing short calculations whereas JavaScript would offer more flexibility in more complex scripts. That's my opinion, anyway.



Also, FormCalc scripts generally execute faster than JavaScript scripts so if speed is a requirement (for large, complex calculations involving multiple fields), you may want to try scripting the calculations in FormCalc rather than JavaScript.



I don't know if you've picked-up on this in your various studies but an example of the differences between FormCalc and JavaScript is the fact that in FormCalc, you just need the field's name in order to assign a value to it as opposed to JavaScript for which you must specify the property to which you're assigning the value:



NumericField1 = 30


The preceding line assigns the number 30 to the field named NumericField1 in FormCalc.



NumericField1.rawValue = 30;


The preceding line does the same thing but in JavaScript.



So I would say that FormCalc is simpler to use but sacrifices flexibility for its simplicity whereas JavaScript is more difficult as it sacrifices simplicity for its flexibility.



Stefan C.

Adobe Systems

Avatar

Former Community Member
Stefan,

Is there a format for sums across subforms?

I have 4 subforms in this form. In subform4 I have a subtotal, which needs to pull amounts from subform 2 and 3 as well as fields in 4.

I have tried every which way formcalc and Javascript.



does it need to identify the subform before the field. subform2.thrs1.rawvalue+subform....?



I have tried it several ways. I can get it to add.

All of my field names are different, if that matters.



my previous form, all the numeric fields were in one subform and I just did

field1+field2+field3.....etc in Formcalc. That isn't working this time.



Thanks again

Avatar

Former Community Member
Yes, you need to specify the subform which contains the fields you're referencing because they aren't in the same scope (same container/subform) as the subtotal field.



I placed 4 numeric fields on a form (named NumericField1/2/3/4), each within its own subform (named subform1/2/3/4). In subform4, I also placed a numeric field called SubTotal. In the SubTotal's Calculate event (language: FormCalc), I used this script:



SubTotal = subform1.NumericField1 + subform2.NumericField2 + subform3.NumericField3 + NumericField4


This makes SubTotal be the total of all numeric fields across multiple subforms.



Stefan C.

Adobe Systems

Avatar

Former Community Member
You're welcome.



Thanks for giving me the link to the completed form. It's a great example of the forms our customers are building. I'll try it out again after April 1st to see those late fees being added in.



Stefan

Adobe Systems

Avatar

Former Community Member
Hello



I have 2 date fields(date/time fields), the Current Date (this is a calendar drop down and aka the date the invoice has been made)

and the payment deadline(basically thats 15 days from the current date)



I read on the Date2Num / Num2Date parts but i am getting 0 as value or nothing



currentd ate field is called INVOICEDATE

and deadline payment field is called DEADLINE



could anyone show me how i can successfully display



23-07-2007 + 15 days = 07/08/2007 ? thank you

Avatar

Level 7
In the "DEADLINE" field's "Calculate" event using FormCalc :



$.rawValue = Num2Date( (Date2Num(INVOICEDATE.rawValue, "DD-MM-YYYY") + 15) , "DD/MM/YYYY")



$.rawValue = value of current field



Date2Num(INVOICEDATE.rawValue, "DD-MM-YYYY") = number of days from epoch date for the INVOICEDATE field with the format of "DD-MM-YYYY"



+ 15 = add 15 days to the above value



Num2Date(..., "DD/MM/YYYY") = convert the computed number for the INVOICEDATE + 15 days, from above, to the date for the number of days from the epoch date into the format of "DD/MM/YYYY"

Avatar

Former Community Member
Thank you for the input, yet it does not work seemingly



it displays from the start 15/01/1900 (what i am actually after is that, when you added a date, it automaticly adds 15 days > deadline)



i 've added this code from your example (thanks)



----- form1.#subform[0].Header.DEADLINE::calculate: - (FormCalc, client) ---------------------------



$.rawValue = Num2Date((Date2Num(INVOICEDATE.rawValue, "DD-MM-YYYY") + 15) , "DD-MM-YYYY")



I tried to refer to the position in the header (i am coming from flash so i am thinking in paths(_root / _parent) maybe thats wrong duno.

i fully understand where you are going to, yet i can't see it happening. thats weird as it sounds perfectly clear.



Both INVOICEDATE / DEADLINE are date/time fields, where i made the DEADLINE a 'read only' so clients don't accidentally edit that.

also both fields have a data pattern of DD-MM-YYYY in the binding & in the fields.



In anycase, thanks for your time, i'll be fiddling some more till i know what i am doing wrong.

Avatar

Former Community Member
Hi



Plz help



I need 2 months javascript calender tht must be called by onclick event of textbox of asp.net 2.0 & if i select current date then previous date must be disabled.



after selecting date must be appear in textbox.I do not want to use calendar control of asp.net 2.0.I want to create in javascript.



Please send code if anyone is having,my email id is

carecareer@gmail.com



open http;//trip.com

in this site just see calendar control ,kuch aisa hi i need.



Thanks

Avatar

Former Community Member
Hi, I'm doing a pdf overtime claim form for a small police department.



This form is a weekly claim form.



I want to automatically populate the date fields for the week, by entering a single date manually, that is the first day of the week, and simply having the rest of the consecutive dates automatically populate.



How do I do this?