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

Calculating hours only relevant hours to a category

New Here ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

Hi Community, I can get my code to sum total annual leave when string includes "AL" however, if the string include another category e.g. "SK" for sick leave, I get NaN sum value error. I need help to make my JavaScript to only see strings value associated with AL and then calculate over 5 days e.g vars A to E.
I may be going about this the completely wrong way.. any help would be appreciated. Thanks

 

//sum annual leave over working week

//Mon to Fri var's a to e

var a = getField("CHset1").valueAsString;
var b = getField("CHset2").valueAsString;
var c = getField("CHset3").valueAsString;
var d = getField("CHset4").valueAsString;
var e = getField("CHset5").valueAsString;

event.value="";

var parts1 = a.split("AL, ");
var parts2 = b.split("AL, ");
var parts3 = c.split("AL, ");
var parts4 = d.split("AL, ");
var parts5 = e.split("AL, ");

if (parts.length >=2)
{
event.value = (1*parts1[1]) + (1*parts2[1]) + (1*parts3[1]) + (1*parts4[1]) + (1*parts5[1]);
}
else event.value = "";

TOPICS
Acrobat SDK and JavaScript

Views

316

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 ,
Apr 26, 2020 Apr 26, 2020

Copy link to clipboard

Copied

Check the console for errors.

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 ,
Apr 26, 2020 Apr 26, 2020

Copy link to clipboard

Copied

You've never defined a variable called "parts". You need to check each partsX variable separately.

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
New Here ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

Thanks try67 and Bernd, i ended up going back to bricks and mortar vars..

 

var a = getField("SET1").valueAsString;

var f = getField("HOURS1").valueAsString;

 

if (a=="AL")event.value = 0;
else if (a=="ISS")event.value = 0;
else if (a=="PH")event.value = 0;
else if (a=="PL")event.value = 0;
else if (a=="PR")event.value = 0;
else if (a=="RP")event.value = f;
else if (a=="SM")event.value = 0;
else if (a=="ST")event.value = 0;
else if (a=="TR")event.value = 0;
else if (a=="K")event.value = 0;

 

else event.value="0";

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 ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

You don't need most of that code. Simply use:

if (a=="RP") event.value = f;

else event.value = 0;

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
New Here ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

LATEST

Thanks try67, the others are needed for variable day entries e.g if AL = annual leave, TR = training etc I then have to take off lunch breaks etc it's all working well now, thanks again. Much appreciated

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