Skip to main content
Participating Frequently
August 26, 2021
Answered

Copying field value (including dropdown choice) to another field

  • August 26, 2021
  • 1 reply
  • 1253 views

Hi

 

I am trying to solve a problem where I am trying to copies value from one field to anothe if a check box has been checked.

 

Here are the fields

 

Acct1Objective                            Dropdown box

Acct1Objectibe_Note                  Text Box

Acct1Time                                   Dropdown box 

Acct1Risk                                    Dropdown box

Acct1Risk_Note                          Text Box

 

Acct2Objective                            Dropdown box

Acct2Objectibe_Note                  Text Box

Acct2Time                                   Dropdown box 

Acct2Risk                                    Dropdown box

Acct2Risk_Note                          Text Box

 

 

If the check box "MirrorAccount " is checked, we would like all the Acct1 fields value to populate Acct2 fields

 

in the checkbox mouse up, I selected to run Java Script and added this code

 

if(this.getField("MirrorAccount").value=="YES")
this.getField("Acct2Objective").value = this.getField("Acct1Objective").value;
else if(this.getField("MirrorAccount").value=="YES")
this.getField("Acct2Objective_Note").value = this.getField("Acct1Objective_Note").value;

else if(this.getField("MirrorAccount").value=="YES")
this.getField("Acct2Time").value = this.getField("Acct1Time").value;

else if(this.getField("MirrorAccount").value=="YES")
this.getField("Acct2Risk").value = this.getField("Acct1Risk").value;

else if(this.getField("MirrorAccount").value=="YES")
this.getField("Acct2Risk_Note").value = this.getField("Acct1Risk_Note").value;

 

 

When I check the box, the scrip runs but only the text boxes populate. The drop down doesnt populate and and still show default values.

 

Is this possible?

 

Thanks

 

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

sorry about that. I missed that.

 

Yes i did use your code and it works ...but I now see what you mean by "replace"

 

The code you provided copied over the export value of the "Acct1" field and it removed all other options.

 

This may not work as we wanted to copy over all fields from Acct1 to Acct2 but still give the user option to adjust any field in Acct2 that should have different value. 

 

Is it possible to keep the options as is under dropdown after coping it over? The dropdown options are same for both fields so that should make it simipler I think.

 

Thanks


Ok, use this code then,it will show same value whitout seting new items:

if(event.target.value!= "Off"){
this.getField("Acct2Objective").currentValueIndices = this.getField("Acct1Objective").currentValueIndices;
this.getField("Acct2Objective_Note").value = this.getField("Acct1Objective_Note").value;
this.getField("Acct2Time").currentValueIndices = this.getField("Acct1Time").currentValueIndices;
this.getField("Acct2Risk").currentValueIndices = this.getField("Acct1Risk").currentValueIndices;
this.getField("Acct2Risk_Note").value = this.getField("Acct1Risk_Note").value;}

1 reply

Nesa Nurani
Community Expert
Community Expert
August 26, 2021

First of all there is no need to call condition for every field,just call it once and put  all fields in curly brackets.

To change value of dropdown use setItems(). There is also issue what do you want to happen with old value in dropdown?

 

See if this code will work for you, use it in checkbox as Mouse Up event:

if(event.target.value!= "Off"){
this.getField("Acct2Objective").setItems([this.getField("Acct1Objective").value]);
this.getField("Acct2Objective_Note").value = this.getField("Acct1Objective_Note").value;
this.getField("Acct2Time").setItems([this.getField("Acct1Time").value]);
this.getField("Acct2Risk").setItems([this.getField("Acct1Risk").value]);
this.getField("Acct2Risk_Note").value = this.getField("Acct1Risk_Note").value;}

NikSCEEAuthor
Participating Frequently
August 26, 2021

Thanks for your assistance Nesa

 

so should my codes be 

 

if (this.getField("MirrorAccount").value=="YES") {
this.getField("Acct2Objective").value = setItems("Acct1Objective").value;
this.getField("Acct2Objective_Note").value = this.getField("Acct1Objective_Note").value;

this.getField("Acct2Time").value = setItems("Acct1Time").value;

this.getField("Acct2Risk").value = setItems("Acct1Risk").value;

this.getField("Acct2Risk_Note").value = this.getField("Acct1Risk_Note").value;

}

 

I tried that but didnt work.

 

And I would like the old values to be replaced.

 

Thanks

Nesa Nurani
Community Expert
Community Expert
August 26, 2021

Have you tried code I posted?