Sometimes it is necessary to call an external process to perform tasks outside of Sage X3. This post will outline pulling data from a 3rd party, and populating a custom table in X3 by calling a .Net executable from X3 4GL code. The process will be done from a .net application which is triggered from an X3 screen. Once the process is complete, the data on the current screen will be refreshed.
This example will use a .net console application, which will accept a parameter from X3. It will perform two steps:
The .net application will be using an external SOAP web service to pull the data and an X3 SOAP web service to load the data to X3.
For this example, the 3rd party web service will return a list of Ship Methods, similar to what is shown below. We will be loading each ship method into a custom table in X3.
The first step will be to create the custom table in X3. This can be done from Development > Data and parameters > Tables > Tables.
Below are the table details:
The columns highlighted are added automatically by X3.
Only one index is required, but I added two here.
Make sure you validate the table.
The next step is to create the subprogram to add or update records in the YECSHIPM table. The code for this is shown below.
############################################################################
## Subprogram: SAVESM
## Description: Save a ship method to custom table YECSHIPM ############################################################################
Subprog SAVESM(SMKEY, COMPID, SMID, CALCUN, SMDESC, STAXKEY)
ValueInteger SMKEY
ValueChar COMPID
ValueChar SMID
ValueChar CALCUN
ValueChar SMDESC
ValueInteger STAXKEY
# Open shipments table
Ifclalev([F:YESM])= 0 : LocalFile YECSHIPM[YESM] : Endif
Read [F:YESM]YESM0=SMKEY
If !fstat
# Update existing records
[F:YESM]YCOMPID = COMPID
[F:YESM]YSMID = SMID
[F:YESM]YCALCUN = CALCUN
[F:YESM]YSMDESC = SMDESC
[F:YESM]YSTAXKEY = STAXKEY
Rewrite [F:YESM]
Else
# Write new record
[F:YESM]YSMKEY = SMKEY
[F:YESM]YCOMPID = COMPID
[F:YESM]YSMID = SMID
[F:YESM]YCALCUN = CALCUN
[F:YESM]YSMDESC = SMDESC
[F:YESM]YSTAXKEY = STAXKEY
Write [F:YESM]
Endif
CloseLocalFile [YESM]
End
The next step is to publish the subprogram created above as a web service. This web service will be called from the .net program to save records from the 3rd party web service to the new X3 table.
Go to Development > Script dictionary > Scripts > Subprograms. Create the subprogram as shown below. Make sure the “Web services” checkbox is checked.
After adding the subprogram, click the “Publication” button to create the web service.
Enter the Publication name and description, as shown below.
After saving the web service, click the “Publication” button to publish it.
Make sure the “Published on” date changes.
The web service is now ready to consume.
For this example, I am adding the ship methods to the customer screen management tab (BPC2).
Add a button to the OBPC window to refresh the ship method values.
Modify SPEBPC code to populate the table on the screen and to call the external .net .exe upon click of the button to refresh the X3 table by calling the 3rd party web service.
As was covered in previous blog posts, several steps will be required to prepare the .Net application to access the X3 SOAP services. These are summarized below, but refer to the original posts referenced below for more details.
Day 4 Consuming X3 Object-Based Web Services from .Net
Day 5 Consuming X3 Subprogram Web Services from .Net
A standard class is used to do the basic authentication for the web service calls.
Create a function in the .net application to retrieve the data from the 3rd party. In this case, I am calling a SOAP web service to retrieve a list of ship methods. This is performed in class ECShipMethod.cs in the sample application.
To test the results, we will go to the X3 customer screen.
Notice that we now have a button called “Refresh Ship Methods”.
Additionally, there is not a block which contains a table of Ship Methods on the Management section. The contents of this grid were retrieved from a 3rd party web service, loaded into a custom X3 table, then refreshed on the screen.
By clicking the “Refresh Ship Methods” button, the latest values will be retrieved and refreshed on the screen.
You now have everything you need to call external executable from a Sage X3 4GL program. Although this is a simple example, this can be used for many different integration requirements where accessing an external program from X3 is necessary.