Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Send Message alert for a time field

Avatar

Level 3

Hello,

I have a finish time field in a memorandum agenda form which I would like an alert (message) sent 2 minutes before the finish time expires.

The script has an error message for the "," on line 4.

var vEnd = Time2Num(ActionsEndTime.formattedValue, "HH:MM") // this is the finish time

var vSec = 2 * 60 * 1000  // time in milliseconds - which is 2 minutes

var vFinish = vEnd - vSec // take away the finish time from 2 minutes to give a new time to trigger to alert

var vcurrent =  form1.ActionsHeaderFrame.DateTimeField1.formattedValue, "HH:MM") // this is the current time field

form1.ActionsHeaderFrame.DateTimeField1.execCalculate() // recalculate a hidden current time field to give the current time

if vcurrent = Num2Time(vFinish, "HH:MM") then  // if the current time equals the finish time - 2 minutes then show message

xfa.host.messageBox("You only have 2 minutes to finish the agenda " ,"Reminder",3,0)

else

""

endif

Can anyone please advise where the formcalc script needs correcting?

Any assistance will be most appreciated

5 Replies

Avatar

Level 10

Hi,

the fourth line in your code is nonsense.

How the value of DateTimeField1 should be formatted?

You need a function such as Time2Num to convert the date into an integer.

var vcurrent =  Time2Num(form1.ActionsHeaderFrame.DateTimeField1.formattedValue, "HH:MM") // this is the current time field

Also, the sixth line is incorrect.
The if expression need surrounding brackets () and an operator like == or eq to check the values.
if (vcurrent == Num2Time(vFinish, "HH:MM")) then

Avatar

Level 3

Thank you for your reply.

I have modified the script as you have suggested:

var vEnd = Time2Num(ActionsEndTime.formattedValue, "HH:MM") // this is the finish time

var vSec = 2 * 60 * 1000  // time in milliseconds - which is 2 minutes

var vFinish = vEnd - vSec // take away the finish time from 2 minutes to give a new time to trigger to alert

var vcurrent =  Time2Num(DateTimeField1.formattedValue, "HH:MM") // this is the current time field

form1.ActionsHeaderFrame.DateTimeField1.execCalculate() // recalculate a hidden current time field to give the current time

if (vcurrent == Num2Time(vFinish, "HH:MM")) then  // if the current time equals the finish time - 2 minutes then show message

xfa.host.messageBox("You only have 2 minutes to finish the agenda " ,"Reminder",3,0)

else

""

endif

I need help with recalculating the current time field as the execCalculate() will update once and remain static.

This is the function in the current time field for the current time  -  DateTimeField1.rawValue = num2time(Time(), TimeFmt(1))

Is there a way to have the time field show like a system clock time and refresh automatically?

I think this will be the only way I can get the formcalc script to work the way it should.

Any suggestions you may have will be most appreciated.

Avatar

Level 10

Hi,

you can put this FormCalc script into the layout:ready event.

$ = Num2Time(Time(), "HH:MM:SS")

The time will be updated everytime the form goes ready again (i.e. when user did changes in a form field or clicks a button).

Avatar

Level 3

thank you for your help.

I have changed the current time field form calc script to a  form ready javascript to show a clock with the current time:

pathToField

="xfa.form.form1.ActionsHeaderFrame.clock";

var t = app.setInterval("obj=new Date();"+pathToField+".rawValue=obj.getHours()+':'+obj.getMinutes()+':'+obj.getSeconds();", 1000);

I have changed the formcalc script to suit, but the alert is still not coming up 2 minutes before the finish time.

var vEnd = Time2Num(ActionsEndTime.formattedValue, "HH:M:SS") // this is the finish time

var vSec = 2 * 60 * 1000  // time in milliseconds - which is 2 minutes

var vFinish = vEnd - vSec // take away the finish time from 2 minutes to give a new time to trigger to alert

var vcurrent =  Time2Num(clock.formattedValue, "HH:M:SS") // this is the current time clock field

if (vcurrent == Num2Time(vFinish, "HH:M:SS")) then  // if the current time equals the finish time - 2 minutes then show message

xfa.host.messageBox("You only have 2 minutes to finish the agenda " ,"Reminder",3,0)

else

""

endif

(also the clock stops running after 6 seconds)?  

If you can provide any assistance I would be very grateful.

Thankyou very much.

Avatar

Level 1

Did you ever get the messaging to work properly if so could you share the code?