• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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;

 

 

 

TOPICS
Acrobat SDK and JavaScript

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 19, 2020 May 19, 2020

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;
i
...

Votes

Translate

Translate
Community Expert ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Hi,

 

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

 

Regards

 

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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 FORMscreen.png

 

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Hi,

 

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

And which version of Acrobat are you using?

 

Regards

 

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Below is the screenshot of my Adobe version

screen.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Attached is the full document level script .. i got this from this community :

function Scand(cFormat, cValue)
{
	var oField = util.scand(cFormat, cValue);
	if(oField ==  null)
	{
		app.alert("Error converting date time string of " + cValue + " with a format of " + cFormat, 1, 0);
	}
	return oField;
} 



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


function DateTime2Min(cFormat, cValue)
{
	oDate = Scand(cFormat, cValue);
	return Math.floor(oDate.getTime()/(1000*60));
} 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

LATEST

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines