Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Nesting JavaScript Syntax

awmackenzie
Level 2
Level 2

I am pretty new to JavaScript, and looking for some nesting help. I can get some IF - ELSE cases to work correctly individually, but when I try to nest it with other ones I am running into some problems. I am trying to look up a condition, but then nest another condition for a language inside of it.

if ( data.Page1.Type.rawValue == 'P' )

   {

   if ( data.ZWPRINTLANG.rawValue == 'EN' )

        {

        this.rawValue = "Scope";

        }

   else if (
data.ZWPRINTLANG.rawValue == 'DE' )

        {

        this.rawValue = "Umfang";

        }

    }

    if (
data.Page1.Type.rawValue == '1' )

   {

   if ( data.ZWPRINTLANG.rawValue == 'EN' )

        {

        this.rawValue = "Approval";

        }

   else if (
data.ZWPRINTLANG.rawValue == 'DE' )

        {

        this.rawValue = "Anerk";

        }

    }

// This was another attempt to make an else case

if ( data.Page1.TF_One.ZART.rawValue != 'P' | '1'
)

{

    if (
data.ZWPRINTLANG.rawValue == 'EN' )

    {
this.rawValue = "Approval";

    }

    else

    {
this.rawValue = "Anerk";

    }

  }

The syntax check is usually correct, but I will only get one set of values to display no matter what selection I am under. Does anyone have some ideas of what I am doing wrong, or how I could correct this?

Thanks,

1 Accepted Solution
MinusZero
Correct answer by
Level 7
Level 7

Have you tried using a switch.

I too have found using ifs can be a problem, so i use an if and a switch. The Livecycle help has information on switch there.

Instead of:

if ( data.Page1.Type.rawValue == 'P' )

   {

   if ( data.ZWPRINTLANG.rawValue == 'EN' )

        {

        this.rawValue = "Scope";

        }

   else if (
data.ZWPRINTLANG.rawValue == 'DE' )

        {

        this.rawValue = "Umfang";

        }

    }

try this:

if ( data.Page1.Type.rawValue == 'P' )

   {

     switch(data.ZWPRINTLANG.rawValue)

     {

     case "EN":

          this.rawValue = "Scope";

          break;

     case "DE":

          this.rawValue = "Umfang";

          break;

     default: //this is what will happen if the above conditions are not met.

          break;

     }

   }

View solution in original post

3 Replies
MinusZero
Correct answer by
Level 7
Level 7

Have you tried using a switch.

I too have found using ifs can be a problem, so i use an if and a switch. The Livecycle help has information on switch there.

Instead of:

if ( data.Page1.Type.rawValue == 'P' )

   {

   if ( data.ZWPRINTLANG.rawValue == 'EN' )

        {

        this.rawValue = "Scope";

        }

   else if (
data.ZWPRINTLANG.rawValue == 'DE' )

        {

        this.rawValue = "Umfang";

        }

    }

try this:

if ( data.Page1.Type.rawValue == 'P' )

   {

     switch(data.ZWPRINTLANG.rawValue)

     {

     case "EN":

          this.rawValue = "Scope";

          break;

     case "DE":

          this.rawValue = "Umfang";

          break;

     default: //this is what will happen if the above conditions are not met.

          break;

     }

   }

View solution in original post

awmackenzie
Level 2
Level 2

Thanks for your help. That did the trick.