How to create a custom OneClick menu item that can prompt the user for input

Document ID:  TEC1778648
Last Modified Date:  08/10/2017
{{active ? 'Hide' : 'Show'}} Technical Document Details

Products

  • CA Spectrum

Releases

  • CA Spectrum:Release:10.0
  • CA Spectrum:Release:10.1
  • CA Spectrum:Release:10.1.1
  • CA Spectrum:Release:10.1.2
  • CA Spectrum:Release:10.2
  • CA Spectrum:Release:10.2.1
  • CA Spectrum:Release:9.3
  • CA Spectrum:Release:9.4
  • CA Spectrum:Release:9.4.1
  • CA Spectrum:Release:9.4.2
  • CA Spectrum:Release:9.4.2.1
  • CA Spectrum:Release:9.4.3

Components

  • ONECLICK:SPCOCK
Introduction:

Spectrum OneClick can be extensively customised to suit user needs. This includes adding menus to the client that can provide functionality beyond the factory settings. Further scripting can add user input to this customisation as this KD will show.

Question:

How can you customise the OneClick menu so that it has an item that first prompts the user to input a value (either string or numeric) and then passes it as an argument ({0}) to a script which is run on the OneClick web server? 

Environment:
Spectrum 10.x
Answer:
To prompt the user for input which can then be used by the script, you would need to customise the script itself to prompt for the value.
 
So, as an example, the following is a script called test_read.sh on a OneClick server running on Linux:

 

#!/bin/sh

echo "Enter word:"

read DATA

echo "You entered the word $DATA"

echo "Press the <Enter> key to continue:"

read DUMMY

 

When run, it prompts the user to enter a word. The user enters a word and presses enter. It returns the word entered by the user and then waits for the user to press the Enter key to continue.

To use this, you would then create a custom menu item under the Tools menu. For example;

<root>

  <menu name="com.aprisma.spectrum.app.swing.window.menu.Tools">

    <item name="Test Script">

      <action>

          <context>

            com.aprisma.spectrum.app.topo.client.render.ModelContext

          </context>

          <context>

            com.aprisma.spectrum.app.alarm.client.group.AlarmContext

          </context>

        <launch-web-server-script>

            <command>/usr/bin/xterm -e /home/myuser/test_read.sh</command>

        </launch-web-server-script>

      </action>

    </item>

  </menu>

</root>

 

The example above requires that the user have xterm software running on their OneClick client system (i.e their PC). However, this can be changed to reflect whatever terminal software you use that has similar capability.

When run, you would see xterm appear as per the attached screenshots. 

test_read-enter_data.png

Enter a word and press enter, it will output that word. Then press Enter again and the xterm disappears.

test_read-output.png

This assumes the Linux DISPLAY environment variable is set to the users client machine (for example; export DISPLAY=localhost:0.0. You would need to set this in the .bashrc / .bash_profile or other environment settings file for whichever particular shell is being used on the Linux based OneClick server).

Another option is to write the script according to the OS and install the script on the client machine and use the <launch-application> tag. If the client OS is Windows, something similar to the following example could be used where <SCRIPT> would be the name of the script to run:

 

<command>cmd.exe /c start "My Script" cmd /c "<SCRIPT> &amp;&amp; pause"</command>

 

Additional Information:

Please help us improve!

Will this information enable you to resolve your issue?

Please tell us what we can do better.

{{feedbackText.length ? feedbackText.length : '0'}}/255

{{status}}

Not what you were looking for?

Search Again >

Product Information

Support by Product >

Communities

Join a Community >