Skip to main content
rakeshk21205956
Inspiring
May 19, 2020 10:26 AM UTC
Answered

Time Caculation - Calculated field value still remains after resetting all the fields.

Hi,

I got this script of calculation of time 

 

on this community and i modified it to suit my form everything is working fine.. but when i reset the form .. everything should be blank or 0 but  the calculated field still keeps the last calculated value;

 

Here is the script (run through calculate tab): 

 

var cStartDate = this.getField("Date").valueAsString;
var cStartTime1 = this.getField("IN_TIME1").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime1 = AdjustMidnight(cStartTime1);

var cEndDate = this.getField("Date").valueAsString;
var cEndTime1 = this.getField("OUT_TIME1").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime1 = AdjustMidnight(cEndTime1);

event.value = 0;
if(cStartDate != "" && cStartTime1 != "" && cEndDate != "" && cEndTime1 != "")
{
var t1 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime1) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime1);
}


var cStartDate = this.getField("Date").valueAsString;
var cStartTime2 = this.getField("IN_TIME2").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime2 = AdjustMidnight(cStartTime2);

var cEndDate = this.getField("Date").valueAsString;
var cEndTime2 = this.getField("OUT_TIME2").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime2 = AdjustMidnight(cEndTime2);

event.value = 0;

if(cStartDate != "" && cStartTime2 != "" && cEndDate != "" && cEndTime2 != "")
{
var t2 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime2) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime2);
}

event.value = t1 + t2;

 

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Bernd Alheit
Bernd AlheitCorrect answer
Community Expert
May 19, 2020 1:28 PM UTC

Try this:

var t1 = "";
var t2 = "";
var cStartDate = this.getField("Date").valueAsString;
var cStartTime1 = this.getField("IN_TIME1").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime1 = AdjustMidnight(cStartTime1);

var cEndDate = this.getField("Date").valueAsString;
var cEndTime1 = this.getField("OUT_TIME1").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime1 = AdjustMidnight(cEndTime1);
event.value = 0;
if(cStartDate != "" && cStartTime1 != "" && cEndDate != "" && cEndTime1 != "")
{
	t1 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime1) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime1);
}




var cStartDate = this.getField("Date").valueAsString;
var cStartTime2 = this.getField("IN_TIME2").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime2 = AdjustMidnight(cStartTime2);

var cEndDate = this.getField("Date").valueAsString;
var cEndTime2 = this.getField("OUT_TIME2").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime2 = AdjustMidnight(cEndTime2);

event.value = 0;

if(cStartDate != "" && cStartTime2 != "" && cEndDate != "" && cEndTime2 != "")
{
	t2 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime2) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime2);
}

event.value = t1 + t2;

10 replies

Inspiring
May 19, 2020 12:06 PM UTC

Have you included in your form a function called 'AdjustMidnight'?

 

Are you getting any earnings in the Acrobat JavaScript console?

 

Have you checked the field calculation order for the form?

Translate
rakeshk21205956
Inspiring
May 19, 2020 12:20 PM UTC

yes i have included 'adjust Midnight function":

 

 

 

function AdjustMidnight(cValue)
{
	if(/^(12)(:\d{2})[ ](am)$/.test(cValue.toLowerCase()))
	{
		cValue = "00" + RegExp.$2 + RegExp.$3;
	}
	return cValue;
} 

 

 

in console window.. it give something : Type Error : f is null

 

There is only one calculated field nothing to bother about calculation order

Translate
BarlaeDC
Community Expert
Community Expert
May 19, 2020 10:57 AM UTC

Hi,

 

How are you resetting the form? a button, custom script.

 

Regards

 

Malcolm

Translate
rakeshk21205956
Inspiring
May 19, 2020 11:14 AM UTC

I tried 3 methods of resetting but still the last calculated value remains... i don't want to make a RESET BUTTON to reset the field .... i want if the user deletes the value individually the calculated field resets itself..

1. RESET the form via inbuilt adobe acrobat > CLEAR FORM

 

2. INDIVIDUALLY deleting all the values from each field.

3. Made a button  and through ACTION tab > RESET A FORM ... this also doesnot work

 

None of them resets the calculated field.

Translate
BarlaeDC
Community Expert
Community Expert
May 19, 2020 11:27 AM UTC

Hi,

 

Are you able to share the document? as that should just work.

And which version of Acrobat are you using?

 

Regards

 

Malcolm

Translate