Author Topic: Get user input on script run  (Read 254 times)

dvenetas

  • Newbie
  • *
  • Posts: 2
Get user input on script run
« on: March 22, 2021, 13:07:27 PM »
Hello!,

Can we accept user input in Archi console when we run a script?

Nashorn readLine() function seems to not be working:

Script Error: javax.script.ScriptException: ReferenceError: "readline" is not defined in file:/D:/projects/archi-script/scripts/restclient.ajs at line number 61
Script Error: javax.script.ScriptException: ReferenceError: "readLine" is not defined in file:/D:/projects/archi-script/scripts/restclient.ajs at line number 61

Also:
    console.log("Give user");
    var buffer = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
    var uname = buffer.readLine();

throws:
    Script Error: java.lang.RuntimeException: java.io.IOException: The handle is invalid

Is there a way to get user to provide input at runtime?
« Last Edit: March 22, 2021, 13:17:58 PM by dvenetas »

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: Get user input on script run
« Reply #1 on: March 22, 2021, 13:15:33 PM »
Hi, the console is for output only.

Please take time to read through the wiki. This section concerns the console and user input:

https://github.com/archimatetool/archi-scripting-plugin/wiki/The-Console%2C-Dialogs-and-Other-Utilities
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

dvenetas

  • Newbie
  • *
  • Posts: 2
Re: Get user input on script run
« Reply #2 on: March 22, 2021, 13:22:10 PM »
Thank you!! hadn't seen this part.

René

  • Newbie
  • *
  • Posts: 7
Re: Get user input on script run
« Reply #3 on: March 25, 2021, 09:27:38 AM »
Are there any other ways for input during run?

Code: [Select]
var name = window.prompt("Please enter your name", "Default Name");
I ask for checkboxes, comboboxes, etc.

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: Get user input on script run
« Reply #4 on: March 25, 2021, 09:29:59 AM »
Are there any other ways for input during run?

Code: [Select]
var name = window.prompt("Please enter your name", "Default Name");
I ask for checkboxes, comboboxes, etc.

Have a look at this topic - https://forum.archimatetool.com/index.php?topic=843.0
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 647
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Get user input on script run
« Reply #5 on: March 25, 2021, 10:02:37 AM »
Hi,

FWIW, I'm working on a small JS library to address this need. The goal is to make it easy to describe the dialog UI, then "run" it and get a data structure (JSON) as a result.

I'll share it as soon as possible, but don't expect something ready before one or two months.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate