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

Javascript help

New Here ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

ok so I am going to try to explain what I am trying to do and hopefully it will make sense.  I have to same Javascript Repeating (with different fields and checkboxes) and only the last 'repeat"  is actually populating to my desired specified text box...I'm sorry this script is long but bear with me. I'm guessing I am missing some script to 'connect' all of the repeats together because I tried it with just 1 'set' of the script and it worked. 

Here is the script (the very end of the scrip that is highlighted red is the only thing populating to my desired text box and it is populating perfectly.):

 

// Get the field values, as strings

var s1 = "Tier 1 Shld:" + getField("Shoulder Tier 1 Date").valueAsString;

var s2 = "V #:" + getField("Shoulder Tier 1 Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=250; i<=257; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

// Get the field values, as strings

var s1 = "Tier 2 Shld:" + getField("Shoulder Tier 2 Date").valueAsString;

var s2 = "V #:" + getField("Shoulder Tier 2 Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=258; i<=267; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

// Get the field values, as strings

var s1 = "Tier 3 Shld:" + getField("Shoulder Tier 3 Date").valueAsString;

var s2 = "V #:" + getField("Shoulder Tier 3 Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=268; i<=273; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

// Get the field values, as strings

var s1 = "Tier 4 Shld:" + getField("Shoulder Tier 4 Date").valueAsString;

var s2 = "V #:" + getField("Shoulder Tier 4 Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=274; i<=309; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

// Get the field values, as strings

var s1 = "Elbow:" + getField("Elbow Screen Date").valueAsString;

var s2 = "V #:" + getField("Elbow Screen Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=310; i<=327; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

// Get the field values, as strings

var s1 = "Wrist:" + getField("Wrist Screen Date").valueAsString;

var s2 = "V #:" + getField("Wrist Screen Visit #").valueAsString;

 

// Combine values, separated by a semicolon

event.value = s1 + ";" + " " + s2;

 

var values = []; 

for (var i=328; i<=353; i++) { 

    var fname = "Checkbox "+i; 

    var f = this.getField(fname); 

    if (f==null) { 

        console.println("Error! Can't find: " + fname); 

        continue; 

    } 

    if (f.valueAsString!="Off") values.push(f.valueAsString); 

}

if (this.getField("UE Notes").valueAsString!="") values.push("UE Find: " + this.getField("UE Notes").valueAsString);

if (this.getField("UE TISSUE DYS").valueAsString!="") values.push("UE Tissue: " + this.getField("UE TISSUE DYS").valueAsString);

event.value += " " + values.join(", ");

 

 

TOPICS
JavaScript

Views

194

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 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

LATEST

Each time you assign a value to event.value you're deleting all the previous ones you applied to it. That's why only your last code section works... So after the first instance of this line:

event.value = ...

You should be using +=, like this:

event.value += ...

That would append the new values to the existing one, instead of overwriting 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