Macro

Previous  Next |  Direct link to this topic

With the macro function, you are able to simulate and script events in SAP Business One. This work much like many of the preset functions in Function Buttons, but here you have much more freedom and advanced options.

image433

The configuration consists:

Macro area which of one big text-area, where you enter the macro-commands that form your user defined functionality

The Macro wizard and Macro Variables in the upper right.

The sample area (just below the text-area) that give you context specific samples.

The Macro Debugger checkbox in the lower right corner

 


The Macro-syntax is as follows:

<Command>(<arguments>);…

Each command can be on one line or on multiple lines as long as they are separated by a “;”

Arguments are entered inside the commands “()”… Some commands do not need any arguments (but still the “()”) while others need more than one argument. Multiple arguments are separated by a “|” char.

In macro's you use the B1UP Dynamic Syntax that you can learn more about here

You can use various Macro command

Commands

Description

Activate(<menuUid>);

or

Activate(<@userTable>);

or

Activate(<@defaultForm>);

or

Activate();

Activate a menu Uid to open a new window or do a specific task on the current window (Switch mode, Go to last Line and so on.)

Alternative you can pass along a user table (Indicate this by the @ as prefix) or a default form. If done so the activation will activate the indicated user tables/default form default window normally located under Tools > User-defined windows / Tools > Default Forms

You also have the option not to pass along a menu Uid/user Table (This is useful when you want to use a command (transfer, set, etc.) on the active window, but that window was not opened by a menu item (Example: if you open the Activity window using the “New activity” button from BP Master Data, you need an Activate(); after the click of the button before you can set data this new window)).

Sample: Activate(2050); will open a new “A/R Sales order” window.

Sample: Activate(@ABC_MYUDT); will open the default window for user table ABC_MYUDT.

Video: Click here to watch more information on how to find menu-uids.

AutoPressNextPopup();

AutoPressNextPopup($[$item.0.0]);

AutoPressNextPopup($[$item.0.0]|timeout);

Call this command to prepare the system to auto-press the next Popup message that appear in the system.

image434

In order to work you need to call this command BEFORE you execute the command that cause the popup. The command can be called with either zero, one or 2 commands.

Argument

Description

Item

On a popup box there can be multiple options (OK/Cancel, Yes/No, Yes/No/Cancel, etc.).

If you want the default button you don’t need to provide this command and B1UP will choose for you but you want a certain result you need to provide the Item Uid of the button you wish to press.

Timeout

In order to prevent that misconfigurations and unforeseen scenarios because unintended auto presses if the intended fails, the Command have a built in timer-function that dismiss an auto-press if the popup does not appear within 5 secs of calling the command. 5 sec is commonly more than enough, but if you have a very long operation you might need to raise the timeout to a higher value than the default 5 sec.

Samples:

AutoPressNextPopup(); press next popup's default button if it happen within 5 sec.

 

AutoPressNextPopup($[$2.0.0]); press next popup's button with Uid = 2 if it happen within 5 sec.

 

AutoPressNextPopup($[$2.0.0]|10); press next popup's button with Uid = 2 if it happen within 10 sec (overridden timeout).

 

Video: How to use the AutoPressNextPopup Command

Panelevel(<newPanelevel>);

Change the current Pane level of a window.

Sample: Panelevel(23); set the current windows pane level to 23 (all items linked to this Pane level will automatically be shown).

NB: This command is needed in order to use the content creator’s new folder (tab) items.

NB: Do not use this to change to another tab (use the click command to do this instead)

ExecuteSQL(<SQL>);

Recommendation: This command have various limitation (example it can't for backward compatibility reasons contain semi-colons in the SQL you wish to execute). For that reason we recommend you instead use the SQL command that is part of the advanced Macro system.

 

Example: @STORE99 = SQL(<your SQL>); 

(The @STORE assignment is needed for this version of the SQL command as it can both execute and retrieve data)

 

***

Original feature description:

 

Executes the SQL.

Sample: ExecuteSQL(UPDATE table SET field = 1 WHERE CardCode = ‘$[$4.0.0]’); executes the SQL and updates a field.

WARNING: Take care when using this command as it does not filter out SQL keywords like drop

Click($[$<item>.<col>.<type>]|<Modifier>);

(.<row> is optional)

(|.<Modifier> is optional)

Click on an item in current form.

Sample: Click($[$103.0.0]) will (if placed on a Business Partner Form) press the Activity button.

Tip: instead of specifying the column you can use keyword “RowHeader” to do a click/select the row-header (The gray block in front of the row)

Sample: Click($[$38.RowsHeader.0.1]) will on a sales order select the 1st row.

TIP: it is possible to use different modifiers with a click. These modifiers (NONE / CTRL / ALT / SHIFT) can for example be used to make multi selects in a table.

image436

Sample: Click($[$3.ROWSHEADER.0.7]|CTRL)

DoubleClick($[$<item>.<col>.<type>|<Modifier>]);

(.<row> is optional)

(|.<Modifier> is optional)

As click but perform a double-click instead.

Tip: instead of specifying the column you can use keyword “RowsHeader” to do a double-click on the row-header (The gray block in front of the row)

Sample: DoubleClick($[$38.RowsHeader.0.1]) will on a sales order double-click the 1st row to show the Line details.

Focus($[$<item>.<col>.<type>]);

(.<row> is optional)

Set focus on an item in current form

Sample: Focus($[$7.0.0])will (if placed on a Business Partner Form) focus the name of the Business Partner.

Transfer(

 $[$<item>.<col>.<type>]|

 $[$<item>.<col>.<type>]);

(.<row> is optional)

If, in your macro, you open a new window, you can use the Transfer command to copy a value from the initial window to the newly opened window.

For this you need 2 arguments:

Argument

Description

SourceItemUid

 

The ItemUid of the item/column located on the initial window you want to copy from

Alternative you can get the data from a previously stored value using the keyword STORE1 à STORE999 (See sample). This is useful if you wish to transfer data to screens that are more 2 windows always from the original screen

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL:<SQL-statement>.

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL_INVARIANT:<SQL-statement>. SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system

TIP: STORE values persist between macro's so you can set a store value in one Macro and then use it in another.

TargetItemUid

The item/column of the item located on the current window you want to copy to

Alternative you can send the data to a store using the keyword STORE1 à STORE10. This is useful if you wish to transfer data to screens that are more 2 windows always from the original screen

Sample 1: Transfer($[$5.0.0]|$[$4.0.0]); will (if activated on a Business Partner window and macro opened an A/R invoice) take the CardCode on the BP and place it on the customer item in the A/R Invoice

Sample 2: Transfer($[$5.0.0]|$[$38.1.0]); will (if activated on an Item Master Data window and macro opened an A/R invoice and transferred the vendor) take the item code on the Item Master data and place it in the item-matrix on the A/R Invoice

Sample 3: Transfer($[$5.0.0]|STORE1); and afterward Transfer(STORE1|$[$38.1.0]); would essentially do the same as Sample 2 but several other windows and commands could happen in between the two commands (Example:  on a window you have some data. You will now open a new window and again from that window open yet another window and send the data to this window. Without the store system that would not be possible since it only works on sending data from previous window to current window)

NB: You cannot set fields that are read-only in the UI. You can try and unlock the field using the "Enable" function but B1UP cannot break the SAP UI logic.

Video: Click here to learn more about using transfer commands

FAQ: When it is possible to read and write data using the dynamic syntax

TransferUdfSidebar(

 $[$<item>.<col>.<type>]|

 $[$<item>.<col>.<type>]);

(.<row> is optional)

This command works like the transfer command but transfer the value to the newly opened windows UDF sidebar.

NB: The sidebar does not need to be shown for this to work

Warning: This command can not be used in Form Load events (SAP SDK Do not allow it)

TransferBack(

 $[$<item>.<col>.<type>]|

 $[$<item>.<col>.<type>]);

(.<row> is optional)

 

This command works almost the same as the transfer command, but it passes data from the newly opened window back to the window that opened it.

TransferBackUdfSidebar(

 $[$<item>.<col>.<type>]|

 $[$<item>.<col>.<type>]);

(.<row> is optional)

This command works like the TransferBack command but transfer the value to the newly opened windows UDF sidebar.

NB: The sidebar does not need to be shown for this to work

Warning: This command can not be used in Form Load events (SAP SDK Do not allow it)

Set($[$<item>.<col>.<type>]| <ValueToSet>);

(.<row> is optional)

 

This command can be used to set a fixed value to an item.

For this you need 2 arguments:

Argument

Description

Item

Standard Formatted search style $[$item.column.type]

Type

Rules

0/String [Default]

As it is

NUMBER

No thousands separators

CURRENCY

Decimal-separator = .

Thousands-separator = ,

DATE

YYYY-MM-DD (2007-04-20 = 20th of April 2007)

ValueToSet

The value to set. Please see the value type how special data should be entered.

TIP: You can use dynamic data from the current window in the value to set using $[$item.column.type].

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL:<SQL-statement>.

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL_INVARIANT:<SQL-statement>. SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system

TIP: If you wish to insert line breaks please use the <newline> keyword to do it.

Sample1: Set($[$4.0.DATE]|2007-01-31); will set the value of item with Uid 4 to 31rd of January 2007 (if item 4 is bound to a Date-field)

Sample2: Set($[$38.11.CURRENCY]|1.75); will set the value of matrix with Uid 38 of its column 11 to 1.75

Sample3: Set($[$16.0.0]|$[$4.0.0]); will set the value of item 16 with the value of item 4.

Sample4 [MSSQL]: Set($[$16.0.0]|SQL:SELECT CardName FROM OCRD WHERE CardCode = $[$4.0.0]); will set the value of item 16 with the result of the SQL

Sample5 [MSSQL]: SET($[$10.0.DATE]|SQL: SELECT CONVERT(VARCHAR(10), GETDATE(), 120));will set the date in item 10 to today’s date. Please note that Conversion of the GetDate to the yyyy-MM-dd format is needed as getdate returns values based on SQL localization/language

 
Sample 6 [HANA]: SET($[$10.0.DATE]|SQL:SELECT TO_CHAR(ADD_DAYS(TO_DATE(CURRENT_DATE, 'yyyy-mm-dd'), 5), 'yyyy-mm-dd') FROM DUMMY); will set the date in item 10 to 5 days in the future.

TIP: If your set-command need to have line breaks you can use the special keyword <NEWLINE> to symbolize this.

Sample6: Set($[$16.0.0]|Line1<NEWLINE>Line2); will set the value of item 16 with the value “Line1”, then a line break and then “Line2”.

NB: You cannot set fields that are read-only in the UI. You can try and unlock the field using the "Enable" function but B1UP cannot break the SAP UI logic.

FAQ: When it is possible to read and write data using the dynamic syntax

SetUdfSidebar($[$<item>.<col>.<type>]| <ValueToSet>);

(.<row> is optional)

This command works like the set command but set the value in a field on the UDF sidebar

NB: The sidebar does not need to be shown for this to work

Warning: This command can not be used in Form Load events (SAP SDK Do not allow it)

MultiSetFromSql($[$<item>.<col>.<type>]|$[$<item>.<col>.<type>]|<SQL>)

This Command works much like the set command, the difference being that you can set multiple values via a SQL command.

 

You can set X number of targets by having a | between each target. the value after the last | should always be the SQL statement.

This command only work if the number of targets is the same as the number of columns in the SQL statement

 

The Different Targets will get the value of their corresponding column in the SQL statement when reading from left to right.

 

Example:

MultiSetFromSql($[$43.0.0]|$[$45.0.0]|SELECT CardName, Balance FROM OCRD WHERE CardCode ='C20000')

 

This macro call will in the fields below getting the value of the corresponding columns

- $[$43.0.0] = CardName

- $[$45.0.0] = Balance

Enable($[$<item>.<col>.<type>]);

 

Enable a disable field.

Disabled

image437

Enabled

image438

NB: Please note that it is not all fields that can be enabled. B1UP cannot break the SAP UI rules.

Disable($[$<item>.<col>.<type>]);

 

Disable an enabled field.

Disabled

image437

Enabled

image438

MassEnable($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

Mass enabling of disabled fields (One or more) using the syntax:

MassEnable($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

MassDisable($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

Mass disabling of enabled fields (One or more) using the syntax:

MassDisable($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

Show($[$<item>.<col>.<type>]);

Shows a previously hidden field, making it visible again

Hide($[$<item>.<col>.<type>]);

Hides a visible field, making it invisible to the user.

MassShow($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

Mass show previously hidden fields, making them visible again (One or more) using the syntax:

MassShow($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

MassHide($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

 

Mass hide visible fields, making them invisible to the user (One or more) using the syntax:

MassHide($[$<item1>.<col>.<type>]|($[$<item1>.<col>.<type>]|…|($[$<itemN>.<col>.<type>]);

ClearValidValues($[$<item>.<col>.<type>])

Clear custom valid values in an item that can hold valid values (Example a combo box).

NB: This cannot be done on system items

Sample 1: ClearValidValues($[$MyUID.0.0]); will remove all valid values from the combo box with Uid ”MyUid”

SetValidValues(($[$<item>.<col>.<type>]|SQL:<SQL>)

Set a custom set of valid values in an item that accept valid values (Example a combo box)

Sample1: SetValidValues($[$MyUID.0.0]|SQL:SELECT CurrCode, CurrName FROM OCRN); will show all currencies as valid values in combo box “MyUid”.

 

Sample2: SetValidValues($[$MyUID.0.0]|SQL:SELECT '', '' UNION ALL SELECT Code, Name FROM OCRY); will show all countries including an empty value in the top in combo box “MyUid”

 

Note: SetValidValues only works on header-level items.

Sleep(<NumberOfseconds>);

Will cause the system to sleep the indicated number of seconds before continuing. This is sometime necessary when you simulate an advanced macro and the client cannot ”keep up” showing the data.

Messagebox(<Message>);

Show a message box with indicated text.

TIP: You can use dynamic data from the current window in the value to set using $[$item.column.type].

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL:<SQL-statement>.

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL_INVARIANT:<SQL-statement>. SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system

NB: Since this will result in a needed user-action (press ok), the rest of the macro after this will wait for closing of the message box.

Statusbar(<Message>|<Type>);

Show a status message (lower left corner)

You have the option to decide the type of the status bar:

Type

Description

E

An error message (Red)

W

A warning message (Blue)

S

A Success message (Green)

N

A clear message (Will remove any currently shown message)

TIP: You can use dynamic data from the current window in the value to set using $[$item.column.type].

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL:<SQL-statement>.

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL_INVARIANT:<SQL-statement>. SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system

Sample1: Statusbar(My error|E) will show an error message (Red).

Sample2: Statusbar(Customer $[$5.0.0] have an error|W) will show a warning message where $[$5.0.0] is the value of item 5 (Blue).

Sample3: Statusbar(SQL:SELECT ItemCode FROM OITM WHERE CardCode = $[$5.0.0]|W) will show a warning message with the result of the SQL as the value (Blue).

Prompt(<2-7 parameters>);

 

Show a prompt with 2 or 3 buttons and depending on the user’s choice run another Universal Function.

You can call this in 6 different ways

Prompt(<Question>|<UF1>);

image440

(If Yes is pressed <UF1> is run, else nothing)

Sample: Prompt(Some question?|UF-001);

Prompt(<Question>|<UF1>|<UF2>);

image440

(If Yes is pressed <UF1> is run, else <UF2> is run)

Sample: Prompt(Some question?|UF-001|UF-002);

Prompt(<Question>|<B1Caption>|<B2Caption>|<UF1>);

image442

(If B1Caption button is pressed <UF1> is run, else nothing)

Sample: Prompt(Some question?|B1Caption|B2Caption|UF-001);

Prompt(<Question>|<B1Caption>|<B2Caption>|<UF1>|<UF2>);

image442

(If B1Caption button is pressed <UF1> is run, else <UF2> is run)

Sample: Prompt(Some question?|B1Caption|B2Caption|UF-001|UF-002);

Prompt(<Question>|<B1Caption>|<B2Caption>|<B3Caption|<UF1>|<UF2>);

image444

(If B1Caption button is pressed <UF1> is run, If B2Caption is pressed <UF2> is run, else nothing)

Sample: Prompt(Some question?|B1Caption|B2Caption|B3Caption|UF-001|UF-002);

 

Prompt(<Question>|<B1Caption>|<B2Caption>|<B3Caption|<UF1>|<UF2>|<UF3>);

image444

(If B1Caption button is pressed <UF1> is run, If B2Caption is pressed <UF2> is run, else nothing)

Sample: Prompt(Some question?|B1Caption|B2Caption|B3Caption|UF-001|UF-002);

RefreshSqlReportTabs();

This command refreshes all the SQL report tabs on the active form

WriteToEventLog(message)

WriteToEventLog(message|Type)

 

Write a message to the currently logged in users Event log (located in %appdata%\Boyum IT\BOY_USABILITY\EventLogs)

As type you can either specify E = Error, W = Warning or I = Information (If you do not provide a type it will be treated as Information).

Sample: WriteToEventLog(Some Error have occurred|E);

Sample: WriteToEventLog(My Message with $[$5.0.0] with keyword in it);

Sample: WriteToEventLog(SQL: SELECT 'Message built from SQL');

UF(<Uid of another universal function);

This command allows you within a Macro to launch another universal function. Use this if you need to perform two or more universal functions on a specific event.

UserQuery(<queryId>)

Enables you to activate a user query in the database. (Use this for the user queries instead of the User defined menu because the menu-Uid of a user query is not static)

Since there is no place in the client where you can find the true id of a user query you will need to use the following SQL sentence to find the key (Called Internal Key (Fieldname: IntrnalKey)).

SELECT T0.IntrnalKey, T0.QName, T1.CatName FROM OUQR T0 JOIN OQCN T1 ON T0.QCategory = T1.CategoryId WHERE T0.QCategory!=-2 ORDER BY T1.CatName, T0.QName

Uppercase($[$<item>.<col>.<type>]);

(.<row> is optional)

Change the casing of a string in an edit text or a column (“my string” >> “MY STRING”)

Sample: Uppercase($[$14.0.0]); Would change Customer reference number to uppercase on a sales order

Sample: Uppercase($[$38.163.0]); Would change Free text of the item matrix on a sales order

Lowercase($[$<item>.<col>.<type>]);

(.<row> is optional)

As Uppercase but send data to lowercase instead  (“MY STRING” >> “my string”)

Firstcase($[$<item>.<col>.<type>]);

(.<row> is optional)

As Uppercase but send data to uppercase for first character of each word instead (“my STRING” >> “My String”)

Blank($[$<item>.<col>.<type>]);

(.<row> is optional)

Blanks the field indicated (Blank = a text field receives an empty value).

NB: You cannot blank a field if it is not allowed by the sap business logic (example: it is not possible to blank the quantity on a document line since it is not allowed to have no value). It is not possible to blank a combo box or checkbox since these are considered always to have a value (use the set command instead)

BlankUdfSidebar($[$<item>.<col>.<type>]);

(.<row> is optional)

Blanks the field indicated on the UDF Sidebar (Blank = a text field receives an empty value).

NB: You cannot blank a field if it is not allowed by the sap business logic (example: it is not possible to blank the quantity on a document line since it is not allowed to have no value). It is not possible to blank a combo box or checkbox since these are considered always to have a value (use the set command instead)

ForeColor($[$<item>.<col>.<type>]|COLORNAME);

Enables you to set the forecolor (text-color) of an item using a color-name. Below shows the supported color-names.

AliceBlue, AntiqueWhite, Aqua, Aquamarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, Firebrick, FloralWhite, ForestGreen,Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, HotTrack, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrodYellow, LightGray, LightGreen, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen

TIP: You can also use a special color-name = “DISABLED” to color in sap’s disabled color (light blue)

Sample: FORECOLOR($[$4.0.0]|RED); will set the forecolor of item 4 to red on the current form.

NB: Not all GUI elements can apply color. The following list show what can be colored and what cannot:

GUI Item type

Fore color

Back color

Button

No

No

Checkbox

(Yes) [Only Code render mode due to SDK bug]

No

Combo box

Yes

Yes

Edit Text

Yes

Yes

Folder (Tab)

No

No

Label

Yes

Yes

Linked Button (Golden arrow)

No

No

Picture

No

No

Rectangle

No

No

Text area

No

No

Matrix Columns

Yes

Yes

Matrix Rows

No

No

Matrix Cells

No

No

BackColor($[$<item>.<col>.<type>]|COLORNAME);

As Forecolor but instead set the background-color of the item.

Sample: BACKCOLOR($[$4.0.0]|Blue); will set the back color of item 4 to blue on the current form.

Block();

Blocks the SAP Event in progress. The rest of the macro will be executed.

Important: The Block() command does not work in SAP Browser Access due to technical limitations.

Close();

Closes the current window.

CloseParent()

If you during a macro open another form using the activate commands, you have the option to Close the form that opened it by calling this CloseParent command. If you have not opened a form calling this command will do the same as the Close command.

SetFormTitle(<new title>)

Set the title of the current form.

Sample:

SetFormTitle(My new window title);

SetCaption($[$<item>.0.0]|<newCaption>)

This command can be used to set the caption of an item (Button, Checkbox, Tab, Label etc.).

Sample:

SetCaption($[$10.0.0]|<My new Caption>);

Freeze();

You can use this command to block in other commands and have them run faster.

NB: Not all operations support freeze/unfreeze and if you forget to call unfreeze or a previous command fails you might end up with an unresponsive window

Sample:

The following sample set a value in both item 16 and item 14. Before setting Freeze is called and after Unfreeze is called. This cause the setting of the two values to be faster and the end user will not see the screen flickering

 

Freeze();

Set($[$16.0.0]|TEST1);

Set($[$14.0.0]|TEST2);

UnFreeze();

Video: Learn more about freeze/unfreeze

UnFreeze();

Use this command to unfreeze a frozen form.

B1P&D(<config-no.>|<action>);

NB: In order to use this feature it is required that the user have a license to B1P&D

This command allows you to initiate a B1 Print and Delivery action.

First parameter is the number of the B1 Print and Delivery report configurations you wish to activate.

image446

Second parameter needed is the type of action you wish to activate you can choose between

Action

Description

Preview

Execute the configurations Print Preview action

Print

Execute the configurations Print action

Email

Execute the configurations Email action

PDF

Execute the configurations PDF action

Fax

Execute the configurations Fax action

Word

Execute the configurations Word action

Excel

Execute the configurations Excel action

ADD

Execute the configurations Add document action

DOCUMENTPRINT

Execute the configurations document Printing action

Sample: B1P&D(1|EMAIL); will go to configuration 1 and launch the email button action (In this case the RA-D004 Report Action)

For more information in B1 Print and Delivery Please see it’s manual.

PopFormStack

This command can be used if you open multiple windows in a macro but need to shift the parent/child relationship one back.

Example: In a macro you are on a Sales order and open a Purchase order. From the purchase order you also open a new window and do some macro logic. Now after this logic you wish the sales order as parent and purchase order as child (at the moment the 3rd window is child and purchase order is parent). If you at this point in your macro call the PopFormStack command you can shift the forms back getting the correct parent /child relationship as before the 3rd window opened.

ExecuteBeasScript(<someBeasScript>);

This command allow you, if you have both B1UP and Beas (version 9.2 PL04 or higher) installed to execute Beas-script code to example have a macro open a Beas window. For more on how Beas-script work see the following url: http://www.beascloud.net/docs/help/beasscript

 

Tip: If you need to send a multi-line Beas-script you can seperate each live with the keyword <cr_lf> keyword (This work on Beas 9.2 PL06 or higher)

SendKeys(<dataToSend>);

Simulate keystrokes on the keyboard.

Warning: You should only use SendKeys if everything else fails as almost actions can be done without SendKeys (More info here). The reason SendKeys are not optimal is it depends on the machine speed and what works on a fast machine might not work on a slow.

The plus sign (+), caret (^), percentage sign (%), tilde (~), and parentheses ( ) have special meanings in SendKeys. To send one of these characters, enclose it within braces ( {}). For example, to send the plus sign, use {+}. Brackets ([ ]) have no special meaning in SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that may be significant when dynamic data exchange (DDE) occurs. To specify brace characters, use {{} and {}}.

To send characters that are not displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below:

Key

Code

Backspace

{BACKSPACE}, {BS}, or {BKSP}

Break

{BREAK}

Caps Lock

{CAPSLOCK}

Delete

{DELETE} or {DEL}

Down Arrow

{DOWN}

End

{END}

Enter

{ENTER}

Esc

{ESC}

Help

{HELP}

Home

{HOME}

Insert

{INSERT} or {INS}

Left Arrow

{LEFT}

Num Lock

{NUMLOCk}

Page Down

{PGDN}

Page Up

{PGUP}

Right Arrow

{RIGHT}

Scroll Lock

{SCROLLLOCK}

Tab

{TAB}

Up Arrow

{UP}

F1, F2, F3...

{F1}, {F2}, {F3}...

To specify key combinations with any of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:

Key

Code

Shift

{+}

Ctrl

{^}

Alt

{%}

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify holding down SHIFT while E and C are pressed, use " +(EC)". To specify holding down SHIFT, while E is pressed, followed by C without SHIFT, use " +EC".

Sample: SendKeys(abc); will enter abc in current field, SendKeys(^P); will initiate the print-dialog while SendKeys(+{F2}) will activate current item's formatted search.

TIP: You can use dynamic data from the current window in the value to set using $[$item.column.type].

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL:<SQL-statement>.

TIP: You can make the value to set come from an SQL-sentence if you start it with SQL_INVARIANT:<SQL-statement>. SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system

TRY, CATCH, IF, ELSEIF, ELSE, WHILE

(Conditional commands)

These advanced keywords are what is called conditional commands and are used for more advanced macro's You can read more about them here

SQL('SELECT * FROM TABLE');

(Conditional helper command)

You can use this command together with the if/while commands to evaluate on results from the database by storing the result in a store.

Example:

@STORE1 = SQL('SELECT CardType FROM OCRD WHERE CardCode = $[$5.0.0]');

IF (@STORE1 = 'S')

BEGIN

    (statement)

END

 

NB: Cannot be used as input to a macro command – only designed for use with the conditional commands

LEN('String to count');

(Conditional helper command)

You can use this command to get the length of a string; you can use a STORE or the dynamic syntax as input.
 

NB: Cannot be used as input to a macro command – only designed for use with the conditional commands

GETDATE();

(Conditional helper command)

You can use this command to get the current data in yyyy-MM-dd format.

Example:

@STORE1 = GETDATE();

IF(@STORE1 > '2012-31-12')

BEGIN

     (statement)

END
 

NB: Cannot be used as input to a macro command – only designed for use with the conditional commands

SortColumn($[$<item>.<col>.<0>]| <Order>);

 

Sort column on a Matrix or Grid in current form. Default is ascending order.

Order

Description

ASC

Sorts the column items in ascending order

DESC

Sorts the column items in descending order

Sample: SortColumn($[$38.1.0]|DESC);will sort the Item No. column on sales order.

DoubleClickColumnHeader($[$<item>.<col>.<0>]);

Can be used to double click a column header (Sort).

Openform(ObjectType|PrimaryKey);

 

 

Can open most forms given an Object type and primary key.

Sample: OpenForm(13|1); opens the A/R Invoice with DocEntry 1.

Sample: OpenForm(13|$[$45.0.0]) will open A/R Invoice with the value in field 45 of the active form

Sample: OpenForm(13|SQL: SELECT '123') will open A/R Invoice with the primary key 123

Sample: OpenForm(112|1) will open the draft that is stored with DocEntry 1 in ODRF table

NB: Requires primary key to be known (Example: DocEntry on A/R Invoice). I is not possible to just reference the document number.

 
Tip: OpenForm can also open Draft documents. The object-type for drafts are 112

CopyTo(ObjectType)

This command can copy values from the current document type to another if the correct object type is given, by activating the correct option on the Copy To button

 

NB: This will fail if the given objecttype is not parth of the Copy to buttons selection

CopyFrom(ObjectType)

This command can copy values from one document type to the current document if the correct object type is given,

by activating the correct option on the Copy From button.

 

NB: This will fail if the given objecttype is not parth of the Copy to buttons selection

TIP: If you want to temporarily not run part of a macro you can comment out the commands by using  //<command>. The command can also be used to document your macro if placed after a command.

Sample of a comment (Here command 4 – Set marked with // and will not be executed)

Activate (2053); //Activate A/R Invoice

Activate(1281); //Switch To Find Mode

Transfer($[$5.0.0]|$[$4.0.0]|STRING); //transfer Item Code

//Set($[$[8.0.0]|*|STRING); //Set Star in Number to Do a Search All

Click(1); //Click on the find Button

NB: Macros can only work on the main window of sap an cannot affect data on the UDF sidebar. You can however read values from the sidebar using the $[<table>.<field>.<type>] syntax