Skip to main content
Inspiring
December 3, 2020
Answered

Need help with custom calculation script

  • December 3, 2020
  • 1 reply
  • 1173 views

Please help, I don't know how to apply these together in the same text field.  Thank you!

event.value = this.getField("WO1").valueAsString;

var a ="";
if (this.getField("Absence1").value == "Vacation (Construction)"){
a="12";
} else if (this.getField("Absence1").value == "Sick (Construction"){
a="34";
} else if (this.getField("Absence1").value == "Vacation (Maintenance)"){
a="56";
} else if (this.getField("Absence1").value == "Sick (Maintenance)"){
a="78";
} else if (this.getField("StandingWorkOrders1").value == "1122334 Maintenance"){
a="1122334";
} else if (this.getField("StandingWorkOrders1").value == "1122334 Maintenance"){
a="1122334";
} else if (this.getField("WO1").value == " "){
a=" ";
}
event.value = a;

 

This topic has been closed for replies.
Correct answer Nesa Nurani

In "Employee1" field first option Is " Lawrence 1234" it should probably be without space like this "Lawrence 1234".
In "Employee2" field you have same code as in "Employee1" code for "AbsencePayTypeJob1Emp1" field you should change to affect "AbsencePayTypeJob1Emp2" instead.
In "WO1EMP2" field you have some code in custom keystroke field. Is that suppose to be there?
There is lot of bugs in your file, and I'm not sure what exactly you mean by "Using two scripts in one field"? what scripts?
Anyway you can use something like this in WO1EMP1 field:

if (this.getField("AbsencePayTypeJob1Emp1").value == "Vacation"){
event.value ="12";
} else if (this.getField("AbsencePayTypeJob1Emp1").value == "Sick"){
event.value="34";
}
else event.value = this.getField("WO1").valueAsString;

Adapt it to your needs. Hope this helps 🙂

1 reply

Inspiring
December 3, 2020

Where in your file should this code go?

What for is first line event.value = this.getField("WO1").valueAsString;?

You have some duplicate lines,missing bracket at "Sick (Construction").

How do you get "Vacation Maintenance and "Sick Maintenance" options?

In dropdown field check "Commit selected value Immediately".

Inspiring
December 3, 2020

I updated the document with more explanation of what I need to do.  I can't post the actual document I'm working on because there are names and employee #'s.  I need the custom calculation script to go into the WO1Emp1 and WO1Emp2 text fields.  The first line event is to populate what has been entered in the work order # text field (WO1).  I put a script in the Employee Name text fields to switch the Absence dropdown list.  I need different work order numbers to populate depending on the employee name selection.  I must have missed checking the 'commit selected value immediately' button, but I still can't get the work order numbers to populate.  I need both WO1Emp1 and WO1Emp2 to populate from WO1 text field, unless an employee chooses absence then I need that number to change.  Eg.  WO1 text field filled in, populates to WO1Emp1 and WO1Emp2, Employee 2 chooses Vacation then WO1Emp2 work order number changes.  I hope this helps!  Thank you so much for helping me out with this!!

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
December 3, 2020

In "Employee1" field first option Is " Lawrence 1234" it should probably be without space like this "Lawrence 1234".
In "Employee2" field you have same code as in "Employee1" code for "AbsencePayTypeJob1Emp1" field you should change to affect "AbsencePayTypeJob1Emp2" instead.
In "WO1EMP2" field you have some code in custom keystroke field. Is that suppose to be there?
There is lot of bugs in your file, and I'm not sure what exactly you mean by "Using two scripts in one field"? what scripts?
Anyway you can use something like this in WO1EMP1 field:

if (this.getField("AbsencePayTypeJob1Emp1").value == "Vacation"){
event.value ="12";
} else if (this.getField("AbsencePayTypeJob1Emp1").value == "Sick"){
event.value="34";
}
else event.value = this.getField("WO1").valueAsString;

Adapt it to your needs. Hope this helps 🙂