Book a Demo

Author Topic: How add a confirmation box in a jscript  (Read 9039 times)

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
How add a confirmation box in a jscript
« on: November 17, 2015, 05:43:37 pm »
Tried window.confirm() in my jscript but EA wouldn't recognise it. Tried Session.prompt("xxx",2) however, it does not seem to return any value regardless Yes or No selected.

How can I add a confirmation box for user to confirm to proceed in Jscript (or should I change to VB)?

Thanks for your help in advance.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How add a confirmation box in a jscript
« Reply #1 on: November 17, 2015, 06:37:34 pm »
peigee,

You need the JScript equivalents of:

      dim oWindowsScriptingHost, iUserResponse
      Set oWindowsScriptingHost = CreateObject("Wscript.Shell")
      
      iUserResponse = oWindowsScriptingHost.popup("<popup Text", ,"<Title>", 32+promptYESNOCANCEL+512)      ' Y/N Cancel, default=Cancel

You need to use the Windows Scripting Host....

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How add a confirmation box in a jscript
« Reply #2 on: November 17, 2015, 06:59:21 pm »
There's an library function in the EAScriptLib MDG technology that does that for you.

Geert

PS. Paolo, in VBScript I find it a lot easier to use msgbox like this:

Code: [Select]
dim response
response = Msgbox ("Text", vbOKCancel+vbQuestion, "Title")
if response = vbOK then
« Last Edit: November 17, 2015, 06:59:52 pm by Geert.Bellekens »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How add a confirmation box in a jscript
« Reply #3 on: November 17, 2015, 07:12:05 pm »
Cool!

Continuous refactoring under way!

Thanks Geert,

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: How add a confirmation box in a jscript
« Reply #4 on: November 18, 2015, 01:41:49 pm »
Thank you Geert.
Based on a sample script in EAScriptLib, I have created the following function to produce the confirm box I have wanted:

/**
 * Displays a 'Confirm' dialog and returns the OK/Cancel button value that the user had selected.
 *
 * @param[in] promptText (String) The text prompt that will be displayed on the confirm dialog.
 * @param[in] title (String) The text that will appear in the confirm dialog's title.
 *
 * @return A Response value representing the choice the user pressed between OK or Cancel buttons
 */
function DLG_Confirm( promptText /* : String */, title /* : String */ ) /* : Number */
{
      // JScript has no intrinsic MsgBox method, therefore we have to steal from VBs
      var vbe = new ActiveXObject("ScriptControl");
      vbe.Language = "VBScript";
      
      return vbe.eval( "MsgBox(\"" + promptText + "\",vbOKCancel+vbQuestion,\"" + title + "\")");
}

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: How add a confirmation box in a jscript
« Reply #5 on: November 18, 2015, 02:03:26 pm »
Using following call may be better:

return vbe.eval( "MsgBox(\"" + promptText + "\",[highlight]vbYesNo[/highlight],\"" + title + "\")");

However, please keep in mind the returned value for yes button would be 6 (not sure what is the matching constant variable in Jscript, certainly not promptOK).