Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Popup menu values

Avatar

Level 2

Lets say I have a button that opens a popup menu with 2 levels:

Fruits> Apple

            Banana

            Melon

Vegetables> Carrot

                     Potato

                     Tomato

Is it possible to get both values? I mean, to receive information if fruits or vegetables was selected and also what kind of fruit/vegetable.

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You could use the cReturn property to encode a value that lets you determine both values, such as;

var choice = app.popUpMenuEx(

     {cName: "Fruits",

      oSubMenu: [ {cName: "Apple", cReturn: "Fruit,Apple" }, {cName: "Banana", cReturn: "Fruit,Banana" }, {cName: "Melon", cReturn: "Fruit,Melon" } ]},

     {cName: "Vegetables",

      oSubMenu: [ {cName: "Carrot", cReturn: "Vegetables,Carrot"}, {cName: "Potato", cReturn: "Vegetables,Potato"}, {cName: "Tomato", cReturn: "Vegetables,Tomato"} ]});

if (choice !== null)

{    

    var selection = choice.split(","); 

    app.alert("You selected the \"" + selection[1] + "\" menu item from the \"" + selection[0] + "\"");

}

Not ideal as you are effectively coding up the menu structure twice (and assumes you will never use a comma character in a menu item name).

Regards

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

You could use the cReturn property to encode a value that lets you determine both values, such as;

var choice = app.popUpMenuEx(

     {cName: "Fruits",

      oSubMenu: [ {cName: "Apple", cReturn: "Fruit,Apple" }, {cName: "Banana", cReturn: "Fruit,Banana" }, {cName: "Melon", cReturn: "Fruit,Melon" } ]},

     {cName: "Vegetables",

      oSubMenu: [ {cName: "Carrot", cReturn: "Vegetables,Carrot"}, {cName: "Potato", cReturn: "Vegetables,Potato"}, {cName: "Tomato", cReturn: "Vegetables,Tomato"} ]});

if (choice !== null)

{    

    var selection = choice.split(","); 

    app.alert("You selected the \"" + selection[1] + "\" menu item from the \"" + selection[0] + "\"");

}

Not ideal as you are effectively coding up the menu structure twice (and assumes you will never use a comma character in a menu item name).

Regards

Bruce

Avatar

Level 2

Thanks Bruce, just what I was looking for.