Copy link to clipboard
Copied
// Sets variables for the entire document and Automatically Populates certain variable based in inputs throughout the document.;
// Assigns variables for populating the rest of the document;
var ord = this.getField("Order").valueAsString;
var bol = this.getField("BOL").valueAsString;
var trac = this.getField("Tractor").valueAsString;
var trail = this.getField("Trailer").valueAsString;
var lead = this.getField("Lead").valueAsString;
var lpay = this.getField("LPay").valueAsString;
var team = this.getField("Team").valueAsString;
var tpay = this.getField("TPay").valueAsString;
var lead1 = this.getField("Lead1").valueAsString;
var lpay1 = this.getField("LPay1").valueAsString;
var team1 = this.getField("Team1").valueAsString;
var tpay1 = this.getField("TPay1").valueAsString;
var olec = this.getField("OLEC").valueAsString;
var trail1 = this.getField("Trailer1").valueAsString;
var refin = this.getField("Refinery").valueAsString;
var unit = this.getField("Unit").valueAsString;
var tmt = this.getField("TMT").value;
var tmt1 = this.getField("TMT1").value;
// Ensures that global variables do not have a values until certain conditions are met;
var ptrip = 0;
var ptrip1 = 0;
var drop = 0;
var drop1 = 0;
var hose = 0;
var border = 0;
var border1 = 0;
var mile = 0;
var mile1 = 0;
var local = 0;
var local1 = 0;
var ldr = 0;
var ldr1 = 0;
var ttpay = 0;
var ttpay1 = 0;
event.value = "";
if (lead.value !== null || lead.value !=="") {
if (team.value !== null || team.value !== "") {
if (lead1.value == null || lead1.value == "") {
event.value=team;
var tpayz = tpay;
var ptrip = 9.45;
var ptrip1 = 9.45;
var drop = 9.45;
var drop1 = 9.45;
var hose = 10.50;
var border = 78.75;
var border1 = 78.75;
var mile = .305;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value == null || team1.value == "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 9.45;
var ptrip1 = 18.9;
var drop = 9.45;
var drop1 = 18.9;
var hose = 10.5;
var border = 78.75;
var border1 = 157.50;
var mile = .305;
var mile1 = .483;
var ldr = tmt;
var ldr1 = tmt1;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value !== null || team1.value !== "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 9.45;
var ptrip1 = 9.45;
var drop = 9.45;
var drop1 = 9.45;
var hose = 10.5;
var border = 78.75;
var border1 = 78.75;
var mile = .305;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt1;
}}
if (team.value == null || team.value == "") {
if ((lead1.value !== null || lead1.value !== "")&&(team1.value == null || team1.value == "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 18.9;
var ptrip1 = 18.9;
var drop = 18.9;
var drop1 = 18.9;
var hose = 10.5;
var border = 157.5;
var border1 = 157.50;
var mile = .483;
var mile1 = .483;
var ldr = tmt;
var ldr1 = tmt1;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value !== null || team1.value !== "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 18.9;
var ptrip1 = 9.45;
var drop = 18.9;
var drop1 = 9.45;
var hose = 10.5;
var border = 157.5;
var border1 = 78.75;
var mile = .483;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt1;
}}}
Copy link to clipboard
Copied
// Sets variables for the entire document and Automatically Populates certain variable based in inputs throughout the document.;
// Assigns variables for populating the rest of the document;
var ord = this.getField("Order").valueAsString;
var bol = this.getField("BOL").valueAsString;
var trac = this.getField("Tractor").valueAsString;
var trail = this.getField("Trailer").valueAsString;
var lead = this.getField("Lead").valueAsString;
var lpay = this.getField("LPay").valueAsString;
var team = this.getField("Team").valueAsString;
var tpay = this.getField("TPay").valueAsString;
var lead1 = this.getField("Lead1").valueAsString;
var lpay1 = this.getField("LPay1").valueAsString;
var team1 = this.getField("Team1").valueAsString;
var tpay1 = this.getField("TPay1").valueAsString;
var olec = this.getField("OLEC").valueAsString;
var trail1 = this.getField("Trailer1").valueAsString;
var refin = this.getField("Refinery").valueAsString;
var unit = this.getField("Unit").valueAsString;
var tmt = this.getField("TMT").value;
var tmt1 = this.getField("TMT1").value;
// Ensures that global variables do not have a values until certain conditions are met;
var ptrip = 0;
var ptrip1 = 0;
var drop = 0;
var drop1 = 0;
var hose = 0;
var border = 0;
var border1 = 0;
var mile = 0;
var mile1 = 0;
var local = 0;
var local1 = 0;
var ldr = 0;
var ldr1 = 0;
var ttpay = 0;
var ttpay1 = 0;
event.value = "";
if (lead.value !== null || lead.value !=="") {
if (team.value !== null || team.value !== "") {
if (lead1.value == null || lead1.value == "") {
event.value=team;
var tpayz = tpay;
var ptrip = 9.45;
var ptrip1 = 9.45;
var drop = 9.45;
var drop1 = 9.45;
var hose = 10.50;
var border = 78.75;
var border1 = 78.75;
var mile = .305;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value == null || team1.value == "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 9.45;
var ptrip1 = 18.9;
var drop = 9.45;
var drop1 = 18.9;
var hose = 10.5;
var border = 78.75;
var border1 = 157.50;
var mile = .305;
var mile1 = .483;
var ldr = tmt;
var ldr1 = tmt1;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value !== null || team1.value !== "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 9.45;
var ptrip1 = 9.45;
var drop = 9.45;
var drop1 = 9.45;
var hose = 10.5;
var border = 78.75;
var border1 = 78.75;
var mile = .305;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt1;
}}
if (team.value == null || team.value == "") {
if ((lead1.value !== null || lead1.value !== "")&&(team1.value == null || team1.value == "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 18.9;
var ptrip1 = 18.9;
var drop = 18.9;
var drop1 = 18.9;
var hose = 10.5;
var border = 157.5;
var border1 = 157.50;
var mile = .483;
var mile1 = .483;
var ldr = tmt;
var ldr1 = tmt1;
}
if ((lead1.value !== null || lead1.value !== "")&&(team1.value !== null || team1.value !== "")) {
event.value=lead1;
var tpayz = lpay1;
var ptrip = 18.9;
var ptrip1 = 9.45;
var drop = 18.9;
var drop1 = 9.45;
var hose = 10.5;
var border = 157.5;
var border1 = 78.75;
var mile = .483;
var mile1 = .305;
var ldr = tmt;
var ldr1 = tmt1;
}}}
Copy link to clipboard
Copied
Lines like this:
if (lead.value !== null || lead.value !=="") {
should be:
if (lead) { // If lead is not an empty string...
A field value will never be equal to the special JavaScript value of null, so there's no need to test against it. In the above example, the variable lead is the value of the field as a string, so it won't have a value property itself.
Copy link to clipboard
Copied
I am not understanding how do I test if the field is empty with your example. Would it be a simple "if (lead) { } else { }" ?
Copy link to clipboard
Copied
Thank You - it should clean it up a lot.
Copy link to clipboard
Copied
Yes.
Copy link to clipboard
Copied
You should only use the "var" keyword to define a variable once. After that refer to it directly, or you're risking having multiple copies of the same variable in different scopes, which is not a good idea.