Requirement: I have a Select List displaying the Fruit Name, and the Display Value and the Return Value for the Fruits are different. I have a button called “Get Selected Fruit Details“
Now, after the page loads, if the user clicks on the “Get Selected Fruit Details” button, it will display an alert message “Please select the Fruit Name“
If the user selects the Fruit Name as Mango. It will display an alert message “Display Value for the Selected Fruit is: Mango and Return Value is: MANGO“
Solution: For the solution of the above requirement follow the steps as shown below:
Step 1: Create a Blank Page with the Name as “Display Select List Value“.
Step 2: Create a Region with Title = “Display Select List Value” and Type = “Static Content”
Step 3: Create an Item inside the Region created in Step 2. Set the properties for the Item as below:
- Name: P9_FRUIT_NAME
- Type: Select List
- List of Values Type: Static Values
- Static Values:
Step 4: Create a button and set the below properties:
- Button Name: P9_GET_SELECTED_FRUIT_DETAILS
- Label: Get Selected Fruit Details
Step 5: Create a Dynamic Action for the button and set the Name as getSelectedFruitDA
For the True outcome of the Dynamic Action set the Action as “Execute JavaScript Code“, and write the below JavaScript code
if ($v('P9_FRUIT_NAME') === '') { apex.message.alert('Please select the Fruit Name'); } else { var retValue, displayValue; retValue = apex.item('P9_FRUIT_NAME').getValue(); displayValue = apex.item('P9_FRUIT_NAME').displayValueFor(retValue); apex.message.alert("Display Value for the Selected Fruit is: " + displayValue + " and Return Value is: " + retValue); }
Save and run the application. Thus, the ran application is shown below:
Click on the “Get Selected Fruit Details” button, it will display an alert message “Please select the Fruit Name“
Select the Fruit Name as Mango, and it will display an alert message “Display Value for the Selected Fruit is: Mango and Return Value is: MANGO“
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
2,687 total views, 2 views today