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

Valores de fstat

Fstat fstat  is a numeric status that is returned upon execution of a database operation, a sequential file operation, or a lock instruction. Syntax fstat Examples # MYTABLE is a table with a key called KEY1, that has a unique component called KEYVAL # Create a record in the table MYTABLE with they key value 1 if it doesn't exist Local File MYTABLE [MYT] Read [MYT]KEY1=1 If fstat [MYT]KEYVAL=1 : Write [MYT] If fstat MSG="The key was created in the mean time" Else MSG="Key created" Endif Else MSG="Key already exists" Endif Details fstat  is always set to '0' if the operation is successfully completed, and has a non-null value if there is an error: In a sequential read ( Getseq  and  Rdseq ),  fstat  is set to '1' at the end of the file. On  Lock ,  fstat  is set to '1' if the lock could not be performed. For a database operation ( Read ,  Look ,  Readlock ,  For ,  Write ,  ...

3 ways to send a mail from code in Sage X3, with more attachments too

Origen Fuente:  https://en.sagedev.it/sagex3/send-mail-from-code-with-attachments-sage-x3/ Autor:  https://en.sagedev.it/category/sagex3/ In this post I’ll show you how to send a mail from adonix code in Sage X3. The points we will face are: 1) Meladx/Send introduction 2) Sending  through  meladx (the best way for me: at the end with just a single code line you send a mail!) 3) Sending  through  Workflow 4) Sending  through  ENVOI_MAIL(…) From AWRKMEL Sending mail from code in Sage X3: Send vs meladx Sage X3 has two native ways for sending mails. The first way is  meladx  executable file, that you can find in  runtime\bin  directory. The seconde one is Send instruction, that was used to send mail through an application of the client station (for more information on “Send GSERMES”  go here ). The Meladx executable Meladx send messages through SMTP/POP3 protocols by means of the mail  ...

How to Install and Manage Sage X3 Add-Ins in Microsoft Office

When you enable an add-in, it adds custom commands and new features to Microsoft Office programs that help increase your productivity. In this blog post, we’ll review how to install the Sage X3 Add-In for MS Excel and what to do if your Sage X3 Add-In is missing. Fuente original: https://www.netatwork.com/how-to-install-and-manage-sage-x3-add-ins-in-ms-office/ How to Install the Sage X3 Add-In in Microsoft Excel Go to Administration > Utilities > Installation > Install addins for Office V11 Image:   V12 Image:   It should begin downloading the exe, open the exe Next > Install   Open Excel > File > Options   Select Add–Ins > Manage: COM Add-ins > Go   Check the “Excel AddIn for Sage” > Ok   You are now ready to export Excel-based reports/grids from Sage X3. How to troubleshoot and fix a missing Sage X3 add-in in Microsoft Excel Open the Microsoft Office product where the  Sage X3  add-in is missing. Go to Options: Se...