Author Topic: How to ask for user input in JScript?  (Read 27589 times)

Christer Lindh

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
How to ask for user input in JScript?
« on: July 10, 2014, 06:47:27 pm »
I'm trying to do some automation in Enterprise Architect using JScript. This is quite new to me, so it's probably a trivial question:

How do I ask for user input? I want to ask the user to enter a string that I can use in the script.

I have searched the EA help and examples and found Session.Input and Session.Prompt. I haven't found any documentation, though. When trying Session.Input nothing seems to happen, and Session.Prompt is only used in the examples with the second argument set to promptOK - I can't find any documentation of what other choices there are...

Helmut Ortmann

  • EA User
  • **
  • Posts: 967
  • Karma: +42/-1
    • View Profile
Re: How to ask for user input in JScript?
« Reply #1 on: July 10, 2014, 07:12:16 pm »
Hi Christer,

I think that's just a JScript Problem. With prompt() method it should work.

see:
http://www.w3schools.com/jsref/met_win_prompt.asp
or other sides.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to ask for user input in JScript?
« Reply #2 on: July 10, 2014, 07:53:37 pm »
Using come of the Cxx languages you may create an own dialogue window which can be used to interact with the user. I'm not sure whether JScript will allow to use that (most likely it won't).

q.

Christer Lindh

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to ask for user input in JScript?
« Reply #3 on: July 10, 2014, 08:17:44 pm »
When trying to use prompt("Some message") as explained in your linked example, I get an error:

An object is expected
(My translation from Swedish)

I suppose I need an object to call the prompt method on... But I don't have a Window object as in the example, as I'm not in a browser...    :(

Helmut Ortmann

  • EA User
  • **
  • Posts: 967
  • Karma: +42/-1
    • View Profile
Re: How to ask for user input in JScript?
« Reply #4 on: July 10, 2014, 10:23:20 pm »
Hi,

the following code works in EA JScript:

var txt = Session.Input("Input value");
Session.Output(txt);


Session is an Object provided and documented by EA (see Online Help).

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: How to ask for user input in JScript?
« Reply #5 on: July 11, 2014, 09:44:56 am »
Quote
When trying Session.Input nothing seems to happen, and Session.Prompt is only used in the examples with the second argument set to promptOK - I can't find any documentation of what other choices there are...
Can you please confirm which program version of Enterprise Architect you are currently running?  (See: Help | About EA)
I think there was a fix in EA 11 for Session.Input, not sure if it worked in previous versions.  The EA 11 help contents also now contains documentation for the Session Object (See: Help | Help Contents > Automation and Scripting > Scripting > Session Object).

Christer Lindh

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to ask for user input in JScript?
« Reply #6 on: July 11, 2014, 04:15:49 pm »
I'm running EA 10. So that is possibly the problem then...

My problem is that I'm at a big company and can't decide which version to run... Is there a workaround?

(I do have EA 11 at home, though, so I will try if it works when I get home. :)   ).

Helmut Ortmann

  • EA User
  • **
  • Posts: 967
  • Karma: +42/-1
    • View Profile
Re: How to ask for user input in JScript?
« Reply #7 on: July 11, 2014, 05:40:07 pm »
Hi,

sometimes when JScript don't offers a feature which is available in VBScript you can call a VB Script from JScript.

Some times ago I have done it with waiting for a period of time. The example I got somewhere on the internet. You may even dynamically create the VB script and then call it from JScript.

Ok, it might require some digging in the internet.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: How to ask for user input in JScript?
« Reply #8 on: July 11, 2014, 09:16:43 pm »
Hi,

Just to confirm, something like:

theVariation = InputBox ("Please enter the variation", "", theElement.Name & "#")
            
Works when using VBScript in Sparx in all versions...so you could have your JScript call a VBScript as Helmut mentions or just re-write in VBScript...

Regards,

Jon.

Christer Lindh

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to ask for user input in JScript?
« Reply #9 on: July 13, 2014, 03:30:50 am »
Thanks, I'll try calling VBScript from JScript at work on Monday.

Can just confirm that Session.Input works perfectly in EA 11 when I try it at home. And there is documentation in the help too.    :)

Thanks for your help
Christer