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

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

    
We recently received a question regarding how to create alert pop-up dialogs using newlook JScript on your IBM i. It was a great question and the tip we have provided is helpful for all, so please find the answer below.


looksoftware provides three different code editors - The Macro Editor, VBScript and JScript. If you are a JScript developer you will also know that JScript is Microsoft's dialect of JavaScript.

If you have tried coding with looksoftware’s script editor to add a JScript dialog box such as confirm, prompt or others, it will return errors. 

Alert_pop-up_dialog_newlook_-_Part_1_-_Alert

Fig 1: Error in Alert Statement


Before we begin to discuss these functions, we would like to run over a couple of things:

Firstly, JavaScript and JScript are just different names for what is really equivalent to ECMAScript standard.

Second, these dialog box functions are not part of the core ECMAScript but they are more like host methods. For example, when you call an alert (“Hello!”) on a web browser, you actually call window.alert(“Hello”) method, and window is the host system’s object that represents an open window in a web browser. That is why you have an error when you call an alert in looksoftware JScript, as there is no such method in JScript and newlook objects – the System object, the App object and the Clipboard object. See the Microsoft JScript runtime error message shown in Fig 1. It is expecting the object for alert – “Object expected”.

 

Is it possible to use alert pop-ups in looksoftware JScript? The answer is “Yes”. We can do this by creating alert function via MsgBox method of App object. See Fig 2.

Alert_pop-up_dialog_newlook_-_Part_1_-_Alert_Fig_2

Fig 2: Alert Function

In this example we have created an alert function which has one parameter. Inside this alert function, App.MsgBox method is called and the parameters passed are the Exclamation icon and the Okay button. You can get more information about MsgBox by pressing the F1 key from the JScript Editor and searching the keyword “MsgBox” or use the Help menu. See the Fig 3 and Fig 4.

Alert_pop-up_dialog_newlook_-_Part_1_-_Alert_Fig_3

Fig 3: Help



Alert_pop-up_dialog_newlook_-_Part_1_-_Alert_Fig_4

Fig 4: Search MsgBox Method

You can use pop-up dialogs in your script with this function. The thing to remember is the prompt argument for MsgBox needs the string value. You can guarantee this by putting an empty string (“” or ‘’) to the argument passing. In JScript adding an empty string to a value is a well-known short cut to make the value a string, regardless of the original value type.

Example: 

App.MsgBox("" + msg, "Alert", nlMsgExclamation , nlMsgOKOnly );  


Summary:

I hope this article has made it clear on how to create a pop-up messages such as “Alert”, “Confirm” or “Prompt”. We show more examples of the other functions in the next blog article, GetModule. Click here to continue through to Part 2.

Read Part 2 of this blog post

Francisco Hoya


Blog Author
Francisco Hoya  
Software Consultant, looksoftware

Topics: ibmi

Subscribe via E-mail


Follow looksoftware