Pass Recordset in Web Service

julkifli33julkifli33 Member Posts: 1,073
Hi All,
are we able to pass record in web service?
This is my code to sync data cross company in 1 tenant.
Company.reset;
if Company.findset then
repeat
	ToGLAccount.ChangeCompany(SyncCompany.Name);
        ToGLAccount.Reset;
        if ToGLAccount.get(ParGLAccountNo) then begin
        	ToGLAccount.TRANSFERFIELDS(FromGLAccount, FALSE);
        	ToGLAccount.MODIFY(TRUE);
        end
        else begin
        	ToGLAccount.TRANSFERFIELDS(FromGLAccount);
        	ToGLAccount.INSERT(TRUE);
        end;
Until Company.Next = 0;

but i just thinking to do for cross tenant via web service.
i dont think we can use transferfields in web service.

any advise?
Thanks.

Answers

  • aniishaniish Member Posts: 27
    Hi,

    You can create a xmlport for table GLAccount with 'AutoUpdate' - true

    create a codeunit with function which will have parameter the xmlport you created.
    Now expose that codeunit through webservice.

    Now you can call webservice URL like below
    Company.reset;
    if Company.findset then
    repeat
      //Call web service with url company name
    Until Company.Next = 0;
    

    Thanks
  • julkifli33julkifli33 Member Posts: 1,073
    edited 2021-08-03
    Hi Aniissh,
    lets say now i have 15 fields to be sync.
    and then in the future i add 2 more fields.
    so it means I need to add 2 more parameter to this codeunit?
  • julkifli33julkifli33 Member Posts: 1,073
    I just thinking to use API (Odata) for different tenant
    so instead of pass field by field.. could it be by 1 recordset?
  • DuikmeesterDuikmeester Member Posts: 304
    You still need to Serialize and Deserialize your data to/from some format. There is no way to pass the actual Recordset. Also the ToGLAccount.MODIFY(TRUE) and INSERT(TRUE) triggering does not trigger in the other company and can have nasty side-effects.
  • julkifli33julkifli33 Member Posts: 1,073
    Hi @Duikmeester
    thanks for your comment.
    so it means my understanding is correct right?
    --> " lets say now i have 15 fields to be sync.
    and then in the future i add 2 more fields.
    so it means I need to add 2 more parameter to this codeunit?"
  • RockWithNAVRockWithNAV Member Posts: 1,139
    You can never have a Record as a part of Parameter in Web Services.

    So if you need to have a record set have an xmlport and receive it as a Bigtext(Can explore TextBuilder Data type if it's Business Central).

    P.S - Normally if its just handful of fields we make it as a direct parameter but if bunch of fields then XmlPort would be the best option as adding 2 more fields as yu saying will be an easier job.
Sign In or Register to comment.