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
BedrockMission!

Learn More

View all

Sign in to view all badges

Nesting JavaScript Syntax

Avatar

Avatar
Validate 1
Level 1
awmackenzie
Level 1

Likes

2 likes

Total Posts

14 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
awmackenzie
Level 1

Likes

2 likes

Total Posts

14 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
awmackenzie
Level 1

11-01-2018

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,

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

14-01-2018

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;

     }

   }

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

15-01-2018

Great! Glad to help.

Avatar

Avatar
Validate 1
Level 1
awmackenzie
Level 1

Likes

2 likes

Total Posts

14 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
awmackenzie
Level 1

Likes

2 likes

Total Posts

14 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
awmackenzie
Level 1

15-01-2018

Thanks for your help. That did the trick.