Expand my Community achievements bar.

SOLVED

Nesting JavaScript Syntax

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
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;

     }

   }

Avatar

Level 2

Thanks for your help. That did the trick.