Ir al contenido principal

Creating Web Services from objects and subprograms


Many Sage X3 objects can be exposed as a web service. Below are the steps on how to do this.
1. Log on to the Safe X3 Client
2. Go to Web Services
Development > Script dictionary > Scripts > Web Services
  • Click "New" on the right navigation bar.
  • Enter the Publication name.
  • Enter a description
  • Select "Object"
  • Enter the Object Name
  • If the object has more than one transaction associated with it, you will be required to select the transaction to publish.
 WebServices2
  • Click "Create", "Save", then "Publication".
WebServices3
  • After the web service is published, the Publication date will be updated.
WebServices4

CREATING CUSTOM SUBPROGRAMS TO CALL AS WEB SERVICE

Custom subprograms can also be created and be called as a web service. The example below retrieves a list of customers that were added or updated within the past n days.

Create the Subprogram

When working with Update 7 and later, Eclipse must be used to create and editor scripts.
1. From Eclipse, go to File / New / Safe X3 Source File.
WebServices6
2. Select the Source folder and enter the File Name.  The source folder will be the folder name that was set up and configured in Eclipse.  This points to a Sage X3 installation and endpoint.
WebServices7
3. A blank window will appear to enter X3 code.
4. Enter the code below. Any parameters that are input variables must be defined with the "Value" keyword. Any parameters that are returned must be defined with the "Variable" keyword. In the example below, UPDDAYS and CUSTID are passed in as parameters, and BPCNUM, BPCNAM, UPDDAT, BPCINV, BPDADD, FCY and CUSGRP are returned.
################################################################
# Program Name: ZCUSTLIST
# Description: Subprogram to Web Service for Customer Listing
# Called by Web Service ZWSCUSTLIS
################################################################
# *Revision Log*
#---------------------------------------------------------------
# Rev Date User Description
#---------------------------------------------------------------
# 000 10/10/2013 D. Hartman Created
################################################################
Subprog CUSTLIST(UPDDAYS, CUSTID, BPCNUM, BPCNAM, UPDDAT, BPCINV,
BPDADD, FCY, CUSGRP)
# Pass number of days since last update
# Returns any customers updated within the last (n) days
Value Integer UPDDAYS
Value Char CUSTID
# Returns array of:
# BPCNUM - Customer Number
# BPCNAM - Customer Name
# UPDDAT - Last Update Date
# BPCINV - Bill to ID
# BPDADD - Default Ship to ID
# FCY - Facility Code
# CUSGRP - Customer Group
Variable Char BPCNUM () ()
Variable Char BPCNAM () ()
Variable Date UPDDAT ()
Variable Char BPCINV () ()
Variable Char BPDADD () ()
Variable Char FCY () ()
Variable Char CUSGRP () ()
# Calculate cutoff date using current date and update days
Date UPDDATE : UPDDATE = date$-UPDDAYS
# Read from Customer Table
Local File BPCUSTOMER [BPC]
Local File BPARTNER [BPR]
# The Web Service is set up to return up to 2000 records. If this is
# reached, break out of loop to avoid error in index.
Local Integer LISTMAX : LISTMAX = 2000
# Fill arrays with Customer Data
Local Integer I : I = 0
Link [BPC] With [BPR]BPR0=[F:BPC]BPCNUM
& As [LNK]
& Where ([F:BPC]UPDDAT >= UPDDATE or [F:BPC]BPCNUM = CUSTID) and [F:BPC]BPCSTA = 2 and [F:BPC]BPCTYP = 1 and [F:BPC]OSTCTL <> 3
For [LNK]
BPCNUM(I) = [BPC]BPCNUM
BPCNAM(I) = [BPC]BPCNAM
UPDDAT(I) = [BPC]UPDDAT
BPCINV(I) = [BPC]BPCINV
BPDADD(I) = [BPC]BPDADD
FCY(I) = [BPR]FCY
CUSGRP(I) = [BPC]BPCGRU
I += 1
If I >= LISTMAX : Break : Endif
Next
End
$INITWS
# Used for testing the web service
#UPDDAYS= 700
Return
$RESULTWS
Return
5. Click F7 to compile and save the code.  If the code compiles successfully, "Compilation finished without error" will appear at the bottom left section of the page.

Save the Sub-Program

  1. Return to Sage X3.
  2. Go to Development > Script dictionary > Scripts > Subprograms
WebServices8
3. Click the "New" link in the right side ribbon.
WebServices9
4. Enter the information as below. "File" should match the file name above, and "Subprograms" should match the name of the subprogram within the file.
 WebServices10
5. Assign an Activity Code, Module and Type.
6. Make sure the "Web services" checkbox is checked.
7. By default, it will set the dimensions on all returned variables to 1. In the code example above, it returns up to 2000 results. Change the "Dim" for each returned variable to 2000.
WebServices11
8. Click "Create", then "Save".
9. Click the "Publication" link in the right ribbon to create the web service.
WebServices12
10. The Web services screen will appear.  Enter the publication name. In this example, the name is "YWSCUSTLIS". Since this was generated from the "ZCUSTLIST" processing and "CUSTLIST" Subprogram, these values are automatically populated in the "Service" section.
WebServices13
  1. Click "Publication" to create the web service.

Entradas populares de este blog

SAGE X3 SILENT IMPORT (IMPORTSIL) WITH ERROR CATCHING

FUENTE ORIGINAL: https://pluginx3.com/en/blog/post/sage-x3-silent-import-importsil-with-error-catching.html You already know how to manually generate a CSV file in order to import it threw a template in Sage X3. But If you wonder how to catch detailed errors after a silent import here is the solution. Sometimes you need to catch the incoming errors in order to alert the end-user regarding an issue. Closed period, wrong date etc …. Unfortunalty the standard Sage X3 silent import function doesn’t natively show the detailed errors during the import process. Call IMPORTSIL([M:IMP2]MODIMP,[M:IMP2]NOMIMP) From GIMPOBJ And the standard function ERR_IMPORT will only show the overall status of the importation and not the detailed errors. IMPORTSIL function is pushing all the log data into a tracefile in order to avoid any popup on end-user screen. So you have a log file available in order to search for errors in it. Sage X3 runtime is using the same principals standards as any shell for log...

Sage X3 Create a new CLOB Text

Here how to create a CLOB text Funprog F_CRELOB ( YABRFIC , YTEXTE ) Value Char YABRFIC Value Char YTEXTE Local Char XXRTFTXT ( 250 ) ( 3 ) XXRTFTXT ( 0 ) = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 MS Sans Serif;}}\viewkind4\uc1\pard\f0\fs17 " XXRTFTXT ( 1 ) = YTEXTE XXRTFTXT ( 2 ) = "\par}" Local Char X_RET Local Integer XXOK Local Char XCHAMPLIEN : XCHAMPLIEN = "YYYY" Global Char YYYY : YYYY = YABRFIC Local Clbfile WWCLOB Local Mask ACLOB [ M :ACL ] Setlob WWCLOB With XXRTFTXT [ M :ACL ] CLOB = WWCLOB Call CRE_CLOB_ACL ( XCHAMPLIEN , XXOK ) From TRTX3TEX Close Local Mask [ M :ACL ] X_RET = YYYY Kill YYYY End X_RET

How To Add a Custom Selector for the Screen Field

Fuente original del artículo:   https://www.rklesolutions.com/blog/how-to-add-a-custom-selector-for-the-screen-field January 5, 2022 By RKL Team Leave a Comment There may be times when you want to add a pop-up window to select a field for a screen. Sometimes this can be handled automatically if the field is a standard X3 object field (i.e. when selecting a product with a type of ITM from the ITMMASTER table). There may be other times where a standard look-up is not available, and some custom code is required to do the selection window. We'll show you how to add a custom selector of your choosing to the screen field. ADD SELECT ON SCREEN FIELD The first step is to add the appropriate code to the field on the screen in Sage X3: Go to  Development > Script Dictionary > Screens Select Your Screen Select the field to have the lookup for  by moving your cursor to it on the screen. The field should show with a blue background. Select a type of "Selection" , and an  ac...