Web service return document



We want to create a Web Service that returns a document (sales order) in array format of bytes (base 64?).

It's posible? Any ideas?

Thants in advance.


  • 0

    It's possible, but it depends on the flow.

    I will assume that you want to retrieve the Sales order (SOH object) printed as PDF and stored somewhere as blob or just file on disk from a calling application (inbound call).

    You need to differentiate how 4GL code can retrieve a clob/blob or file and then how it can be transferred by inbound SOAP Web Services.

    You can store any kind of Clob/Blob document in Sage X3, create a subprogram later published as SOAP web services with
    - Document key to read as input parameter

    - Clob output to receive the content

    this will be encoded in base 64 and returned to caller as such. Once you receive it, you can decode64 it and rename the file accordingly. It can be anything, product images, sales orders pdf files, etc.
    Here is an example extracted from the SOAP Web Services training about getting product images:
    1- create a subprog to get the file as blob:

    Value Char ITM
    Variable Blbfile IMG
    Variable Integer RET
    Local File CBLOB [CBB]
    If ITM=""
      RET = 0
    Read [CBB]CBB0= "ITM";ITM;""
    If fstat=0
      IMG = [F:CBB]BLOB
      RET = 1
      RET = 0

    2- if you want to retrieve the image locally and read it as .jpeg:

    Openo "c:\Temp\image.jpeg",0 Using [XIMG]
    Putseq 1, IMG Using [XIMG] #Putseq is writing to file in binary format,  not ascii
    Openo Using [XIMG]

    3- just publish your subprogram as a web services.

    Fields IMG will the contain the blob as base64 in the SOAP Web Services

    if you want to read an image from disk and not from a db blob, then just load the image by using getseq 4GL command instead of putseq

  • 0 in reply to Bruno Gonzalez

    Hi Bruno,

    thanks for the response. We have a sales order in PDF format stored in folder and we want to send this in binary format by a web service.

    From what you comment, the way is as follows:

    - read de file and convert to binary format with putseq command.

    - save the binary file

    - read that file from subprog (GET_ITM_IMAGE) and send file as Blbfile with web service

    It's right?

    Thanks for all!


  • 0 in reply to Carles Homs Ferrer

    Carles, I believe it is important to clarify:
    - Is the PDF requested by SOAP Web Services from an external application to Sage X3?
    - is the PDF being sent by Sage X3 to an external application ?

    Depending if it is inbound or oubound, it changes things a bit.

    In all case, you need to get the file content by

    - declaring a string variable long enough to store the base64 content (255 chars max or use clob variable)

    - Get the file as base64 by using getseq command, unload into your variable

    for instance, something like:

    local char MYSTRINGVAR (255)
    Openi #YOURPATHTOFILE using [YYY]
    getseq 1, MYSTRINGVAR
    Openi using [YYY]

    Please bear in mind that you can also transfer files via emails using Sage X3 workflows, or via sftp or equivalent.

  • 0 in reply to Bruno Gonzalez

    Hi again,

    We are trying to return the clob text using a representation. Some time ago we saw this website How to add a clob text to a representation class @ L.V. Expertise X3 (lvexpertisex3.com) that explains how to add a clob text to a representation.

    Even though we have been trying to follow these and tweak it to fullfill our needs, we have not been able to make it work. When we use postman (HTTP request) to check whether the representation returns data or no, we receive all the information excluding the clob field, which has a "null" value all the time.

    In addition to this, we have also checked standard representations and if we use postman once again, the clob fields data is not returned.

    How can I define the representation in order to get a clob field that is stored in a table?

    Thanks in advances!

  • 0 in reply to Carles Homs Ferrer

    In REST web service if we have a clob property displayed in a representation, it is not managed with a method, post, put, get or delete on the representation.
    A blob property is manageable in post put, delete but not in get.
    In the blob you can put binary or text (in base64).

    If you want to read a blob or a clob you can go through a web service different from the get on the representation 
    http://<x3 machine>:8124/api1/x3/erp/X3ERPV12_SEED/CDOC('C_ZT~%C2%A8~ZCLOB~%C2%A8~ZCLASS_ZT~%C2%A8~C1~%C2%A8~~%C2 %A8~')


    http://<x3 machine>:8124/api1/x3/erp/X3ERPV12_SEED/BDOC('C_ZT~%C2%A8~ZBLOBIMG~%C2%A8~ZCLASS_ZT~%C2%A8~C1~%C2%A8~IMG~% C2%A8~')

    In my case i have a class ZT, representation ZT.

    For find the url, you can use the deverloper tol in your internet browser.

  • 0 in reply to Olivier Mantel

    Hi Oliver,

    I have 2 questions:

    1. CDOC/BDOC is a custom rest web service created by you?

    2. Representation ZT have a clob filed? wich specific type is it?

    Thanks in advance!

Reply Children
No Data