Use a Button to launch an action script

A very common usage of automation scripting is to develop the action logic when a button is pressed in an application. The concept I will describe in this blog is principal the same for the following three scenarios:

  • A button included in the application with the application designer (I will show this in this blog)
  • A Toolbar Menu entry (Icon Toolbar)
  • A Action Menu entry

So what are the steps to create a button and run the script on it?

  • Create a new Signature Option and assign it to the appropriate user group.
  • Create the new Button, Toolbar Menu or Action Menu in Application Designer.
  • Create a new Automation Script with an Action launchpoint.

I would like to take a demo scenario with very simple scripting so we can concentrate mainly on the other stuff. In the Item Master Application when a new item is created the Commodity Group and Commodity Code has to be selected for each item. Let’s say you are mostly entering new Laptop items and you would like to get a “Default Commodity” button to fill in these two fields with default values like this:

Selection_028

That’s basically all, so lets start.

Create a new Signature Option and assign it to the appropriate user group

To create a new Signature Option we need to go the the Application Designer:

  • Go To > System Configuration > Platform Configuration > Application Designer
  • Select the application ITEM (Item Master) in the List View.
  • Now you go the “Select Action” menu and select the “Add/Modify Signature Options” entry.

Menu_030

  • In the dialog which opens hit the “New Row” button to add a new Signature Option.
  • Create a new Option with a name and a comment like follows:

Selection_031

And now the important part!!! Did you recognized the “Advanced Signature Options” section which is closed by default? Open it and check the following point:

Selection_032

If you forget to check this entry your button will never work and your script will never run.

  • Click on OK to close the dialog.
  • Assign the new Signature Option to a Security Group where your user is in (e.G. MAXADMIN for testing). You will find the new signature Option in the ITEM Application section:Selection_033
  • Don’t forget to logoff / logon to the Server before you proceed.

Create the new Button in Application Designer

After a new logon proceed in the Application Designer:

 

  • Go To > System Configuration > Platform Configuration > Application Designer
  • Select the application ITEM (Item Master) in the List View.
  • In the Application design screen select the “Item” Tab from the application.
    Selection_035
  • Open the Control Palette dialog in the Toolbar: Selection_034
  • From the Control Palette Drag and Drop the “Button Group” symbol to the “Commodity Group” Text. The button group should occur above the Commodity Group.
  • Right Click on the “pushbutton…” and select the properties Menu
  • Enter the following Values:
    • Label: “Default Commodity”
    • Event: “DEFCOMM” (This is the Name of the Action we will define later)
    • Signature Option (on page two): DEFCOMM (the one you created before)
      Selection_036

That is basically all you need to do in Application Designer. Your Button should now look as follows:

Selection_037

Save your work.

 

Create and test the automation Script

The new script will be created in:

Go To > System Configuration > Plattform Configuration > Automation Scripts

In the Select “Select Action” box select “Create > Script with Action Launchpoint”.

Menu_038

Fill in the dialog as follows and press “Next” when done:

Selection_039

Interesting here is the Object field. This field is the MBO Object your are in and which your script will get as the implicit “mbo” Variable.

In the next dialog we need to fill in some more values. It is always good practise to name the action, launchpoint and script the same (unless you will have multiple launchpoints with different meanings for a script).

Selection_040

Press the “Next” button when filled in.

In the last dialog you will have to paste in the following script code:

itemMbo = mbo  # @UndefinedVariable
itemMbo.setValue("COMMODITYGROUP", "43211500")
itemMbo.setValue("COMMODITY", "43211503")

Press “Create” to create the automation script. The Action object will be automatically created in background. Don’t forget this when you need to transport your development to another system.

Test the new solution

To test your new button:

Go To > Inventory > Item Master

Create a new Item and press the new Button. The Commodity Group and Code should be automatically be filled in. Congratulations!

Selection_041

 

Leave a Reply

Your email address will not be published. Required fields are marked *