Skip to main content
Known Participant
July 24, 2019
Answered

Script not running at document open

  • July 24, 2019
  • 2 replies
  • 941 views

I have the following script in my "Documents JavaScript." It is my understanding putting the script in "Documents JavaScript." should cause the script to execute each time the document is opened.

The intent is to look at three fields in a specific row... if all are $0.00 and a date has been put in the date field for that row, then remove the date. If any one of the three checked fields has a value >$0.00 then leave the date. The field is defaulted to currency, thus the Dollar sign. I have tried both with and w/o the "$." This is repeated 8 times as there are a possible 8 rows all with the fields as noted in the script.This is not working on testing. What am I missing or is this not going to work as is?

var v1 = this.getField("FUEL COST TOTAL1").value;

var v2 = this.getField("REEFER COST TOTAL1").value;

var v3 = this.getField("DEF COST TOTAL1").value;

var v4 = this.getField("DATE_FS1").value;

var v5 = this.getField("FUEL COST TOTAL2").value;

var v6 = this.getField("REEFER COST TOTAL2").value;

var v7 = this.getField("DEF COST TOTAL2").value;

var v8 = this.getField("DATE_FS2").value;

var v9 = this.getField("FUEL COST TOTAL3").value;

var v10 = this.getField("REEFER COST TOTAL3").value;

var v11 = this.getField("DEF COST TOTAL3").value;

var v12 = this.getField("DATE_FS3").value;

var v13 = this.getField("FUEL COST TOTAL4").value;

var v14 = this.getField("REEFER COST TOTAL4").value;

var v15 = this.getField("DEF COST TOTAL4").value;

var v16 = this.getField("DATE_FS4").value;

var v17 = this.getField("FUEL COST TOTAL5").value;

var v18 = this.getField("REEFER COST TOTAL5").value;

var v19 = this.getField("DEF COST TOTAL5").value;

var v20 = this.getField("DATE_FS5").value;

var v21 = this.getField("FUEL COST TOTAL6").value;

var v22 = this.getField("REEFER COST TOTAL6").value;

var v23 = this.getField("DEF COST TOTAL6").value;

var v24 = this.getField("DATE_FS6").value;

var v25 = this.getField("FUEL COST TOTAL7").value;

var v26 = this.getField("REEFER COST TOTAL7").value;

var v27 = this.getField("DEF COST TOTAL7").value;

var v28 = this.getField("DATE_FS4").value;

var v29 = this.getField("FUEL COST TOTAL8").value;

var v30 = this.getField("REEFER COST TOTAL8").value;

var v31 = this.getField("DEF COST TOTAL8").value;

var v32 = this.getField("DATE_FS8").value;

// Check to see if Date 1 is entered with no purchases

if (v1 == "0.00" && v2 == "0.00" && v3 == "0.00") {

    v4.value = "";

}

// Check to see if Date 2 is entered with no purchases

if (v5 == "0.00" && v6 == "0.00" && v7 == "0.00") {

    v8.value = "";

}

// Check to see if Date 3 is entered with no purchases

if (v9 == "0.00" && v10 == "0.00" && v11 == "0.00") {

    v12.value = "";

}

// Check to see if Date 4 is entered with no purchases

if (v13 == "0.00" && v14 == "0.00" && v15 == "0.00") {

    v16.value = "";

}

// Check to see if Date 5 is entered with no purchases

if (v17 == "0.00" && v18 == "0.00" && v19 == "0.00") {

    v20.value = "";

}

// Check to see if Date 6 is entered with no purchases

if (v21 == "0.00" && v22 == "0.00" && v23 == "0.00") {

    v24.value = "";

}

// Check to see if Date 7 is entered with no purchases

if (v25 == "0.00" && v26 == "0.00" && v27 == "0.00") {

    v28.value = "";

}

// Check to see if Date 8 is entered with no purchases

if (v29 == "0.00" && v30 == "0.00" && v31 == "0.00") {

    v32.value = "";

}

This topic has been closed for replies.
Correct answer try67

Your variables are strings, not Field objects, so you can't use them to re-apply a value to the field.

To fix it change these lines:

v4.value = "";

To:

this.getField("DATE_FS1").value = "";

Or if you still want to use a variable for it change its definition from:

var v4 = this.getField("DATE_FS1").value;

To:

var v4 = this.getField("DATE_FS1");

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 24, 2019

Your variables are strings, not Field objects, so you can't use them to re-apply a value to the field.

To fix it change these lines:

v4.value = "";

To:

this.getField("DATE_FS1").value = "";

Or if you still want to use a variable for it change its definition from:

var v4 = this.getField("DATE_FS1").value;

To:

var v4 = this.getField("DATE_FS1");

Known Participant
July 25, 2019

Thank you for the help, With slight modification to my original script The script now works as desired.

Corrected script:

var v1 = this.getField("FUEL COST TOTAL1").value;

var v2 = this.getField("REEFER COST TOTAL1").value;

var v3 = this.getField("DEF COST TOTAL1").value;

var v4 = this.getField("FUEL COST TOTAL2").value;

var v5 = this.getField("REEFER COST TOTAL2").value;

var v6 = this.getField("DEF COST TOTAL2").value;

var v7 = this.getField("FUEL COST TOTAL3").value;

var v8 = this.getField("REEFER COST TOTAL3").value;

var v9 = this.getField("DEF COST TOTAL3").value;

var v10 = this.getField("FUEL COST TOTAL4").value;

var v11 = this.getField("REEFER COST TOTAL4").value;

var v12 = this.getField("DEF COST TOTAL4").value;

var v13 = this.getField("FUEL COST TOTAL5").value;

var v14 = this.getField("REEFER COST TOTAL5").value;

var v15 = this.getField("DEF COST TOTAL5").value;

var v16 = this.getField("FUEL COST TOTAL6").value;

var v17 = this.getField("REEFER COST TOTAL6").value;

var v18 = this.getField("DEF COST TOTAL6").value;

var v19 = this.getField("FUEL COST TOTAL7").value;

var v20 = this.getField("REEFER COST TOTAL7").value;

var v21 = this.getField("DEF COST TOTAL7").value;

var v22 = this.getField("FUEL COST TOTAL8").value;

var v23 = this.getField("REEFER COST TOTAL8").value;

var v24 = this.getField("DEF COST TOTAL8").value;

{

// Check to see if Date 1 is entered with no purchases

if (v1 == "0.00" && v2 == "0.00" && v3 == "0.00") {

    this.getField("DATE_FS1").value = "";

    }

}

{

// Check to see if Date 2 is entered with no purchases

if (v4 == "0.00" && v5 == "0.00" && v6 == "0.00") {

    this.getField("DATE_FS2").value = "";

    }

}

{

// Check to see if Date 3 is entered with no purchases

if (v7 == "0.00" && v8 == "0.00" && v9 == "0.00") {

    this.getField("DATE_FS3").value = "";

    }

}

{

// Check to see if Date 4 is entered with no purchases

if (v10 == "0.00" && v11 == "0.00" && v12 == "0.00") {

    this.getField("DATE_FS4").value = "";

    }

}

{

// Check to see if Date 5 is entered with no purchases

if (v13 == "0.00" && v14 == "0.00" && v15 == "0.00") {

    this.getField("DATE_FS5").value = "";

    }

}

{

// Check to see if Date 6 is entered with no purchases

if (v16 == "0.00" && v17 == "0.00" && v18 == "0.00") {

    this.getField("DATE_FS6").value = "";

    }

}

{

// Check to see if Date 7 is entered with no purchases

if (v19 == "0.00" && v20 == "0.00" && v21 == "0.00") {

    this.getField("DATE_FS7").value = "";

    }

}

{

// Check to see if Date 8 is entered with no purchases

if (v22 == "0.00" && v23 == "0.00" && v24 == "0.00") {

    this.getField("DATE_FS8").value = "";

    }

}

try67
Community Expert
Community Expert
July 25, 2019

You should remove the variables you're not using any longer.

Bernd Alheit
Community Expert
Community Expert
July 24, 2019

Your code doesn't change any field.