Part 2: How to create alert pop-up dialogs on IBM i using newlook JScript

Posted by Francisco Hoya on Dec 18, 2014 6:38:42 PM

Welcome to Part 2 of the blog How to create Alert pop-up dialogs on IBM i using newlook JScript.

In Part 1 of this blog post, we covered:  

  • JavaScript and JScript are implementations of ECMAScript
  • JavaScript alert, confirm and prompt are not core methods of ECMAScript but are host methods
  • looksoftware is the host of the looksoftware JScript editor
  • looksoftware doesn’t have alert, confirm and prompt methods
  • We created a solution with an alert function using looksoftware App object’s MsgBox method

In Part 2 of this blog post, we will create confirm and prompt functions, and show you an easy way to use these function within scripts using GetModule

Function Confirm

confirm is similar to alert. It has two options - OK and Cancel. Clicking OK returns true, clicking Cancel returns false (See Fig 1).


Fig 1: Confirm Pop-up Box

Once again we will use MsgBox methods of App object to create a function named confirm refer to Fig 2 below:


Fig 2: Confirm Function

- This function has one parameter which is a string for the message in a pop-up dialog box

[2] - Display question icon (nlMsgQuestion) and two buttons (nlMsgOKCancel) for OK and Cancel

[3] – At the end of the function it tests if a user clicked OK (nlMsgOK) or not, then returns true for OK or false for Cancel. Please refer to our Help for MsgBox to get more information.


For a quick test, let’s put it all together in a script (See Fig 3). We have created a script named test and put the function alert and the function confirm.

[1] - The variable called answer will receive the result from confirm which is true or false
[2] - Then alert will show this result in a pop-up box.


Fig 3: Test

Run the Debug Solution to see if these functions are working as expected. If you have already run the solution in debug mode than select your script to debug.


Fig 4:  Debug

Function Prompt

Dialog box for prompt is showing an input box to enter text as follow.


Fig 5: Prompt

The MsgBox we used so far doesn’t have the user input function and we can’t use the MsgBox method for creating the prompt function. However, we can use InputBox Macro Action for this purpose. Fig 6 shows the macro named UtilMacro using an InputBox macro action. 


Fig 6: UtilMacro

The InputBox action defines three arguments (See the Label on line 1):

  • varInputTitle for Title
  • varInputMessage for Message
  • varInputResponse for Value

They are all user defined variables which are accessible globally between Macro, VBScript and JScript . This way we can share these global values in JScript . See the following code snippet calling the UtilMacro’s sub macro InputBox and accessing the user input value by using GetValue method.

return App.GetValue("varInputResponse");

The full prompt function is shown in Fig 7. You need the alert function and UtilMacro macro shown in Fig 6 to test. Run the solution in debug mode and run your script to debug (See Fig 4).


Fig 7: Prompt Function


How to use GetModule

You can copy the functions in your script anytime you need them but there is a better way rather than copying whole functions. We can make this creating a script which has all these functions and calling them from other scripts (See Fig 8). A script named Util is created and it has all functions - Alert, confirm and prompt


Fig 8: Script Util

Let’s create another script for testing. See the script test in Fig 9. You can use the GetModule method to call these functions. With the GetModule method you can think of a script as a module, providing a better way to call other scripts within your script. You can also use functions in other scripts in this way without copying the functions. Run the script in debug mode then you can see the same results.


Fig 9: GetModule(“Utill”).alert

If you want to use the function alert like window.alert please see Fig 10.


Fig 10: GetModule(“Util)

Now you have an answer on how to get alert, confirm and prompt in looksoftware JScript Editor and a better way to call functions in other scripts. If you wish to execute an external script then it is recommended that you use the GetModule method. The RunMacro method should not be used to call other scripts within your script, however it is used to call Macros from within your script.

I hope this has helped you.

If you missed Part 1 please click here or on the button below. Please also find useful video resources via the newlook feature videos button below, and thanks for reading the article.

Read Part 1 of this blog post

Click to view the newlook feature videos

Francisco Hoya

Blog Author
Francisco Hoya  
Software Consultant, looksoftware

Topics: ibmi