.NET Snippet

Previous  Next |  Direct link to this topic

NB: Your SAP Partner need to have a “SAP Business One Software Development Kit” license from SAP to be allowed to use this feature. Read more here

The .NET Snippet system allows you to create new keywords that can be used in B1 Validation System and Universal Function – Macro. The keywords can be made using either C# or VB and it gives you the full power of the SAP SDK. This gives you the option to create advanced C#/VB code that you can then expose as a simple keyword.

The .NET Snippet is useful in cases where you need to access something very specific that B1UP does not expose by default.

For example if you only want to run a B1 Validation when you are on a specific pane on the form.

To access the .NET Snippet you can right click the SQL field on the B1 Validation System or the Macro Field in Universal Function – Macro.

image050image052

This will open the window:

DotNetSnippet_Window

Field

Description

Code

Each configuration will need a unique code. The code is also what will be used as a Keyword.

This means that if you call the keyword GetPaneLevel you can access it later as @GetPaneLevel.

Description

 You can give it a description if needed.

Code text area

The code field allows you to write .NET code (Either C# or VB.NET) and have it executed when the Universal function is called.

As this is a keyword system you are expected to return a string.

RETURN ”MY COOL KEYWORD”;

From the code you have access to 3 variables:

Variable

Description

Company

This is a company-object (DI-API) connected to the current database. From this object you will be able to add/update Business objects.

NB: YOU SHOULD NEVER DISCONNECT THIS COMPANY OBJECT

Application

This is an application-object (UI-API) connected to the current client. From this object you will be able to manipulate the client data (forms and menus).

Form

This is the current form as an object. You can use it to get information about the forms data.

 

TIP: IF YOU HAVE SO MUCH CODE THAT IT CAN’T BE IN THE TEXT-AREA YOU CAN WRITE:

CODEFROMFILE(<PATH TO CODE-FILE>)

THIS WILL RESULT THAT THE RAW DATA IN THE FILE WILL BE LOADED AS THE CODE TO EXECUTE.

 

 

References

In this field you have the option to add dll-references to the code. As default the following references are already included:

-         System.dll

-         Interop.SAPbobsCOM.dll

-         Interop.SAPbouiCOM.dll

To create the sample where it returns the Pane Level of the form you can write a bit of C# as below:

DotNetSnippet_Sample_DotNet

You can then use the keyword in either the B1 Validation System or the Universal Function – Macro:

DotNetSnippet_Sample_B1Validation