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

Custom Calculation Script not working, need help

Engaged ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

I'm not sure why this isn't working and I'm hoping someone can help me out. 

I have seperate text fields each named 'PayType1' to 'PayType 40', where I've entered a custom calculation script to have the numbers I need to populate to. 

I need the numbers to populate from one text field named 'EmpStatus', unless a number has populated to one of the text fields named 'PT1' to 'PT40', which I have populate depending on a selection made from a dropdown list.  EmpStatus works but if a number populates to PT1 it doesn't populate and I don't know why.  This is what I'm entering in the 'PayType' text fields as a custom calculation script...

 

if (this.getField("EmpStatus").value == "Regular"){
event.value ="1";
} else if (this.getField("EmpStatus").value == "Temp"){
event.value="2";
} else if (this.getField("EmpStatus").value == "Auxiliary"){
event.value="3";
}
else event.value = this.getField("PT1").valueAsString;

TOPICS
Create PDFs , JavaScript

Views

2.7K

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 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Your script is working fine, it's just conditions are not set in right order for what you want to achive.

If there is one of three values in "EmpStatus" condition for "PT1" will not work because it's last,if you delete or change value from "EmpStatus" then condition for "PT1" will work. So to make it work put it on top.

if(this.getField("PT1").valueAsString != "")
event.value = this.getField("PT1").value;

...then use rest of your code whitout 'else' line (last line).

TIP: Setting 40 calculations can slow down your file, you could use  'for loop' script in one of the fields that would do entire job.

 

 

 

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 05, 2021 May 05, 2021

Copy link to clipboard

Copied

I'm actually having a huge problem with the file size but my knowledge is pretty basic.  I've just been trying to figure out how to fix it with the little I do know.  How would I apply a 'for loop' script and where would I need to put it?  I attached the file with a change in the names for privacy.  Any help would be so appreciated!  I think it's all the codes in the second table (Time Entry Export) where I've put custom calculation scripts in the PayType and Pay Type Description fields to populate, among other things I'm sure.  I'm no expert, but I think that's what mainly taking up a lot of the file space and causing problems when the user fills it all in.  I've been stressing with trying to think of ways I can fix it.

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 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Scripts add almost nothing to the file-size, and 40 calculations should work just fine. That's not the issue.

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
Enthusiast ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

There is more then 300 calculations in that file which can be reduced with for loop as other member here suggest.If it doesn't slow down your file leave it just fix bugs you have,otherwise think of hire professional to help you with it.

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 06, 2021 May 06, 2021

Copy link to clipboard

Copied

Mostly your space is used by large amount of fields, if you want to know what is using space go to File->Save as other->Optimized PDF and then in upper right corner click ' audit space usage'.

 

"PayTypeDesc" fields have same code, but code in some fields isn't writed in same order (in some fields it starts with "empStatus" in others with "AbsencePayTypeDesc" so it won't work same.

What happen if all 3 fields have value "empStatus","AbsencePayTypeDesc" and "Acting"? only the first right condition will execute, so having codes not writed in same order won't show same result.

 

 

 

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 06, 2021 May 06, 2021

Copy link to clipboard

Copied

It works the way I need it to so it's all fine.  It does randomly freeze up and says 'not responding; after a while of filling out the fields.  It worked fine before but I recently had to make it bigger.  I'm not sure why that happens.  I guess I'll just suggest to keep saving the document as it's filled out.  Thanks though 🙂 I appreciate the input!

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 05, 2022 May 05, 2022

Copy link to clipboard

Copied

LATEST

Hi Nesa, 

I’m really hoping you can help.  I’m able to make my form work with my limited knowledge but I would really like to do as you suggest and use a ‘for loop’ script.  I’ve researched to try and figure it out myself but I’m struggling.  I’m using the following custom calculation in each ‘PayType1’ to ‘PayType40’ fields but how would change it so I can enter in one field to do the entire job?  I attached a simplified version of what I have in the actual form but I’m sure I can figure it out if I have an idea of what to do.  I’d super appreciate any help. Thank you!

//PayType Custom Calculation Script

var a ="";

if (this.getField("AbsencePayTypeDesc1").value == "Vacation"){

    a="300";

} else if (this.getField("AbsencePayTypeDesc1").value == "Sick"){

    a="400";

} else if (this.getField("AbsencePayTypeDesc1").value == "Stat Holiday"){

    a="530";

} else if (this.getField("Acting1").value == "Acting"){

    a="11";

} else if (this.getField("EmpStatus").value == "Regular"){

    a="1";

} else if (this.getField("EmpStatus").value == "Temp"){

    a="2";

} else if (this.getField("EmpStatus").value == "Auxiliary"){

    a="3";

}

event.value = a;

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