Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

code improvement - "For Loop", help needed!

Avatar

Level 1

Hi All,

Is that possible help me to improve the following code in "For Loop" ?

I have 7 radio button, sh1_g to sh7_g, there are a lot of combination to go through.

code as follows:

if(sh1_g.rawValue == "1" && sh2_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=sh2_name.rawValue;

          Page5.g2_nric.rawValue=sh2_nric.rawValue;

}

else if(sh1_g.rawValue == "1" && sh2_g.rawValue == "2")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

else if(sh1_g.rawValue == "2" && sh2_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh2_name.rawValue;

          Page4.g1_nric.rawValue=sh2_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

else

{

          Page4.g1_name.rawValue=null;

          Page4.g1_nric.rawValue=null;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

Thanks!

Marcus

3 Replies

Avatar

Former Community Member

if(sh1_g.rawValue == "1") {

     Page4.g1_name.rawValue=sh1_name.rawValue;

     Page4.g1_nric.rawValue=sh1_nric.rawValue;

     if (sh2_g.rawValue == "1") {

          Page5.g2_name.rawValue=sh2_name.rawValue;

          Page5.g2_nric.rawValue=sh2_nric.rawValue;

     } else

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

     }

} else {

     if (sh2_g.rawValue == "1") {

          Page4.g1_name.rawValue=sh2_name.rawValue;

          Page4.g1_nric.rawValue=sh2_nric.rawValue;

     } else {

          Page4.g1_name.rawValue=null;

          Page4.g1_nric.rawValue=null;

     }

     Page5.g2_name.rawValue=null;

     Page5.g2_nric.rawValue=null;

}

Avatar

Level 1

Hi Steve,

This is the scenerio:

I have a list of Shareholders Name, 7 Row as follows:

Page 1: Shareholder List

                                   Shareholder Name                             Guarantor (Radio Button Yes/No)

Yes/ No (radio button)

Yes/ No (radio button)

Yes/ No (radio button)

Yes/ No (radio button)

Yes/ No (radio button)

Yes/ No (radio button)

Yes/ No (radio button)

Page 2

Guarantor 1 Name

Page 3

Guarantor 2 Name

Page 4

Guarantor 3 Name

Page 5

Guarantor 4 Name

If I Type in the Name at shareholder list, and checked "Yes", the shareholder's name will auto populate at the Guarantor 1, Guarantor 2, Guarantor 3 & Guarantor 4,

Code for 1st radio button:

if(sh1_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

}

else

{

          Page4.g1_name.rawValue=null;

          Page4.g1_nric.rawValue=null;

}

Code for 2nd radio button:

if(sh1_g.rawValue == "1" && sh2_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=sh2_name.rawValue;

          Page5.g2_nric.rawValue=sh2_nric.rawValue;

}

else if(sh1_g.rawValue == "1" && sh2_g.rawValue == "2")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

else if(sh1_g.rawValue == "2" && sh2_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh2_name.rawValue;

          Page4.g1_nric.rawValue=sh2_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

else

{

          Page4.g1_name.rawValue=null;

          Page4.g1_nric.rawValue=null;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

}

Code for 3rd Radio Button:

if(sh1_g.rawValue == "1" && sh2_g.rawValue == "1" && sh3_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=sh2_name.rawValue;

          Page5.g2_nric.rawValue=sh2_nric.rawValue;

          Page6.g3_name.rawValue=sh3_name.rawValue;

          Page6.g3_nric.rawValue=sh3_nric.rawValue;

}

else if(sh1_g.rawValue == "2" && sh2_g.rawValue == "1" && sh3_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh2_name.rawValue;

          Page4.g1_nric.rawValue=sh2_nric.rawValue;

          Page5.g2_name.rawValue=sh3_name.rawValue;

          Page5.g2_nric.rawValue=sh3_nric.rawValue;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else if(sh1_g.rawValue == "1" && sh2_g.rawValue == "2" && sh3_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=sh3_name.rawValue;

          Page5.g2_nric.rawValue=sh3_nric.rawValue;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else if(sh1_g.rawValue == "2" && sh2_g.rawValue == "2" && sh3_g.rawValue == "1")

{

    Page4.g1_name.rawValue=sh3_name.rawValue;

          Page4.g1_nric.rawValue=sh3_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else if(sh1_g.rawValue == "1" && sh2_g.rawValue == "1" && sh3_g.rawValue == "2")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=sh2_name.rawValue;

          Page5.g2_nric.rawValue=sh2_nric.rawValue;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else if(sh1_g.rawValue == "2" && sh2_g.rawValue == "1" && sh3_g.rawValue == "2")

{

    Page4.g1_name.rawValue=sh2_name.rawValue;

          Page4.g1_nric.rawValue=sh2_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else if(sh1_g.rawValue == "1" && sh2_g.rawValue == "2" && sh3_g.rawValue == "2")

{

    Page4.g1_name.rawValue=sh1_name.rawValue;

          Page4.g1_nric.rawValue=sh1_nric.rawValue;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

else

{

          Page4.g1_name.rawValue=null;

          Page4.g1_nric.rawValue=null;

          Page5.g2_name.rawValue=null;

          Page5.g2_nric.rawValue=null;

          Page6.g3_name.rawValue=null;

          Page6.g3_nric.rawValue=null;

}

The code for 4th, 5th, 6th & 7th radio button is getting longer and longer, reason being, there are a lot of combination out there.

I know it is possible to use For Loop to do this, method: Evaluate the radio button value and populate the rawvalue accordingly.

Help appreciate, if any 1 can suggest a solutions or help me to write a For Loop to over come this problem.

Thank you.

Marcus

Avatar

Former Community Member

To use a loop, the items must be arrays. Adding complexity to your situation is related items from a data perspective being spread across pages and subforms for layout. If you create a schema for your data and create a data connection based on that schema, then bind your fields to the schema, you can separate data reference out from layout. It will then make it much easier to loop on the data yet still have your layout as is.