Framework:Macros

From CoPlanner 11
Jump to navigationJump to search

A macro is a group of actions, each of which carries out a certain operation such as the opening of a form or the execution of a server command. With macros, you can automate tasks that need to be performed frequently. For instance, you can create a macro that executes an import, i.e. deletes data, re-imports them and then opens a report if a user calls it up through a menu item.

To give properties to the macro, open the macro by clicking the “Design“ button, or by clicking on the context menu with the right mouse button, or by double-clicking the batch designer. With the “New” menu item, you can also create a new macro here. Several actions can be defined in the batch designer. Additionally, you can assign a comment to these actions.

Available actions:

  • NavAction
  • ServerCommand
  • Message

The created actions will then be executed in the batch designer one after the other. The order of execution can be changed with the File:Icon Pfeil Up.jpg and File:Icon Pfeil Down.jpg buttons.

Framework, Batch designer

Depending on the chosen action, the user has different configuration options available.

NavAction

With NavActions, you can open masks, dimensions etc. In addition, NavActions can also execute formulae, imports etc. A description of all NavActions you find here.

Framework, NavAction

ServerCommand

Various different server commands are available for choice

Command Description
DBC Execute Procedure Stored Procedures can be executed. The name of the Stored Procedure must coincide precisely with the name of the Stored Procedure of the SQL Server (for instance sp_calc_table). In addition, parameters of the Stored Procedure can be transferred. The individual parameters are separated with “;”, and they all start with an “@” (for instance: @param1=FirstParameter;@param2=SecondParameter). The Database Connection String looks as follows: Server=ServerName;Initial Catalog=DatabaseName;user id=MyUserId; password=MyPassword
Delete plan datasets The ServerCommand ‘Delete datasets’ deletes all datasets of the selected plan of all plan-dependant tables. If the plan is set to “Current plan”, only datasets of the plan where the user is logged in are deleted.
Formula activate This ServerCommand can activate or deactivate formulae. In addition, the formula “Macro active” can be set.
Activate formulae Activates the CoPlanner formulae.
Deactivate formulae Deactivates the CoPlanner formulae.
Reload PlanSecurity Reloads the security for the current plan.
Copy plan Copies all datasets from one plan to another plan.
Copy table datasets All datasets within the selected plan of a table are copied into another table. In addition, XML filters for the datasets can be specified here.
Delete table datasets All datasets within the selected plan of a table are deleted. In addition, XML filters for the datasets can be specified here.

Apart from the selection of the table, it is also necessary to select a plan for deletion. This can be done by explicitly selecting a certain plan, or with the “Current plan” function, which automatically selects the plan of the login. If the option “independent of plan” is chosen, the data of the selected table are deleted from all plans! See example below.

Recalculate table of this plan All datasets within the selected plan of a table are recalculated. In addition, XML filters for the datasets can be specified here..
Start import on the Server Starts an import object on the Server. As each import object returns a ‘successful’ message, this ‘successful’ message can be suppressed with the “Activate feedback” parameter.
Synchronize database Forces the synchronization of the CoPlanner server and the SQL server before further CoPlanner ServerCommands are executed.

Complete pending calculations Forces the execution of all pending calculations (formulae). Then a database synchronization is forced before further ServerCommands are executed.

Execute formula Executes the selected formula.
Change session parameter Changes the session properties. Here it can be specified, for instance, that the session context is executed in macro mode so that subsequently further formulae will be executed whose property is set to ‘Execute in macro mode’. For this purpose, please specify the following parameters:

To change over to macro mode: MacroMode=1 To leave the macro mode: MacroMode=0

Example: Delete table datasets:

The task is to use one macro in order to delete all datasets from a table that belong to the logged in plan. For this purpose, create a new macro and select “ServerCommand” as the action and perform the settings as shown in the following Figure.

Framework, Makro – Delete table rows

Call up the filter editor by clicking the button.

Framework, Macro – Filter - Editor

From the combination list field, select the entry “BAB_Plan” and “Bike GmbH” in the “Enterprise” filter. By clicking the ‘Add’ button, this setting is applied. By replacing the criterion with the @Session_Enterprise_ID@ session variable, this filter always refers to the logged in enterprise.

If you need this filter several times, you can save it with the “Save filter” command and reinsert it with “Load filter”.

Message

Information about the execution of the macro at the client can be shown to the user with messages. For this purpose, enter the message text, message title and message type.

Framework, Macro - Message

Types of messages

Error
File:Fw Makrodesigner Meldung Fehler.jpg
Framework, Macro - Message - Error
Exception
File:Fw Makrodesigner Meldung Ausnahme.jpg
Framework, Macro - Message - Exception
Information
File:Fw Makrodesigner Meldung Information.jpg
Framework, Macro - Message - Information
Question
File:Fw Makrodesigner Meldung Frage.jpg
Framework, Macro - Message - Question
No Symbol
File:Fw Makrodesigner Meldung Kein Symbol.jpg
Framework, Macro - Message - No Symbol
Stop
File:Fw Makrodesigner Meldung Stop.jpg
Framework, Macro - Message - Stop
Warning
File:Fw Makrodesigner Meldung Warnung.jpg
Framework, Macro - Message - Warning


Fortsetzungsbedingung

Die Fortsetzungsbedingung dient dazu, um die Weiterführung des Makros steuern zu können. Wird sie aktiv geschalten, muss die Bedingung zutreffen, um mit dem Makro fortzufahren. Trifft die Bedingung nicht zu, wird das Makro genau an der Stelle beendet. Es besteht die Möglichkeit mittels einer Meldung auf den Abbruch hinzuweisen.

File:Fw Makrodesigner Fortsetzungsbedingung Inaktiv.jpg
Framework, Makro - Fortsetzungsbedingung - Inaktiv
File:Fw Makrodesigner Fortsetzungsbedingung Aktiv.jpg
Framework, Makro - Fortsetzungsbedingung - Aktiv

Es müssen für die Bedingung beide Ausdrucksfelder befüllt werden. Ein Ausdruck kann eine Abfrage zum CoPlanner Server mittels der Funktionen die das Rechenwerk bereitstellt, ein SQL Statement auf die CoPlanner Systemdatenbank oder ein konstanter Wert sein. Die Abfrage zum CoPlanner Server wird mittels Transform=, eine SQL Server Abfrage mittels Sql= gekennzeichnet. Ein konstanter Wert wird ohne besondere Kennung eingetragen.

Beispiele:

File:Fw Makrodesigner Fortsetzungsbedingung Sql kombiniert mit CoPlanner Abfrage.jpg
Framework, Makro - Fortsetzungsbedingung – Sql kombiniert mit CoPlanner Abfrage
File:Fw Makrodesigner Fortsetzungsbedingung Sql kombiniert mit konstantem Wert.jpg
Framework, Makro - Fortsetzungsbedingung - Sql kombiniert mit konstantem Wert

Bei konstanten Werten muss der Datentyp beachtet werden. Liefert die SQL bzw. CoPlanner Abfrage als Ergebnis eine Zeichenfolge, muss der Wert unter einfache Anführungszeichen gestellt werden. Liefert die Abfrage als Ergebnis einen numerischen Wert, entfallen die An-führungszeichen. Wird eine SQL Abfrage definiert, welche nicht genau einen Wert, sondern eine Ergebnistabelle liefert, wird der Wert der linken, oberen Ecke für den Vergleich herangezogen.

Framework, Makro - Fortsetzungsbedingung - Ergebnis bei Abfrage mit Tabelle als Ergebnis
Framework, Makro - Fortsetzungsbedingung - Ergebnis bei Abfrage mit Tabelle als Ergebnis

Liefert die SQL Abfrage keine einzige Zeile, so kann dies mittels der Konstante ‘NULL‘ abgefragt werden.

File:Fw Makrodesigner Fortsetzungsbedingung Abfrage ob Datensätze geliefert werden.jpg
Framework, Makro - Fortsetzungsbedingung - Abfrage ob Datensätze geliefert werden

Ausdrücke können auch mit CoPlanner Sessionvariablen versehen werden. Vor der eigent-lichen Evaluierung des Ausdrucks werden diese durch den entsprechenden Wert ersetzt. Sessionvariablen können auch als konstanter Wert verwendet werden.

File:Fw Makrodesigner Fortsetzungsbedingung Abfrage mit Session Variable.jpg
Framework, Makro - Fortsetzungsbedingung - Abfrage mit Session Variable

Ist die Option „Meldung bei Nichterfüllung“ aktiviert, wird bei Abbruch des Makros dem Be-nutzer die Meldung mit dem entsprechenden Text angezeigt. Ist die Option nicht aktiv, wird das Makro ohne weitere Meldung beendet.

File:Fw Makrodesigner Fortsetzungsbedingung Meldung bei Nichterfüllung.jpg
Framework, Makro - Fortsetzungsbedingung - Meldung bei Nichterfüllung