Options

Codeunit Web Service with XMLPort

bblackstonebblackstone Member Posts: 4
edited 2015-09-21 in NAV Three Tier
I have a web services question using codeunits and XMLPorts as web services. I would like to be able use an XMLPort as a parameter for a codeunit web service, but I want the XMLPort to point to tables set a Temporary, so the data is not automatically inserted into the database when called. I would like to be able to read the data passed in to the XMLPort, then process it in the codeunit.

I have tried creating an XMLPort with Purchase Header and Purchase Lines, setting both records as Temporary=Yes. I have then create a codeunit, and created a method "SavePurchasOrder", with the XMLPort as the method parameter. When this is published, I am able to call the method as a web service, but I believe the XMLPort data, since it is Temporary, is out of scope when I try to access it in the codeunit.

I have even tried creating a function in the XMLPort called GetData, tried passing the temp table data through this, but it returns empty tables.

Is this possible to do, without writing the XMLPort data to a record and reading it in the codeunit?

Thanks!

Answers

  • Options
    krikikriki Member, Moderator Posts: 9,090
    If you want to access the temptable from the codeunit, you have to create a function like "GetData" with the temptable as a parameter. You need to define the variable as "VAR"!
    and in the function, you need to loop the temptable in the globals of the XML-port and insert the records in the parameter-temptable of the function.

    In the XML-port, when you have a record filled up, you need to INSERT it into a temptable in the globals of the XML-port.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    bblackstonebblackstone Member Posts: 4
    Thanks kriki, I did try the GetData function, but I'll try again this weekend, to be sure I used the VAR parameter.
  • Options
    bblackstonebblackstone Member Posts: 4
    Solved - thanks kriki. I was missing the global temp table in the XMLPort, and instead was just trying to read out the XMLPort table to the VAR parameter table. To get this to work, as suggested by kriki, I created a separate Global table, marked as Temp, and filled this table OnAfterInsert of the XMLPort table. Then I created a GetData function on the XMLPort, with a VAR temp table as a parameter. I filled this temp table by looping through the values in the Global table. This will allow me to pass the values around without actually inserting them into a table. If I'm overlooking an easier approach to this, please let me know! Thanks!
Sign In or Register to comment.