Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Web service: Add line to PO

Posted on by Microsoft Employee

I'm trying to add a new purch line to an existing purchase order via the web services. I've gone through the list of available services and tried quite a few of them, to no avail. The one that makes the most sense would be Page 54, "Lines", as that is the purchase lines page.

I tried sending the Document Nbr of the PO I want to add the line to, but receive the following error message: "Field Document No. is readonly!"

However if I don't include it, I get an error saying the Document No is required!

This happened with a few of the "Lines" pages when I tried them as well. 

Does anyone know how to add a new line to an existing purchase order via the web services?

Categories:
  • Suggested answer
    keoma Profile Picture
    keoma 32,671 on at
    RE: Web service: Add line to PO

    the logic of the keys is not known. not sure why you need that.

    as i wrote you can use the read(key) function or the readmultiple(filter...) function.  with the needed filter settings you get the wanted records.

    for usage of the readmultiple fct. goto docs.microsoft.com/.../readmultiple-operation

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    The solution we came up with is to regularly sync the keys to a table in our database using the ReadMultiple service, so we have the unique key for the existing purchase order headers. We can then use that key in Update or UpdateMultiple to add a line. In proof of concept testing, this seems to work.

    It would be much better if we didn't have to sync the keys in this manner but could create them instead. However per my last comment, the Purchase Order key is a combination of the simple key Franz mentioned and every single line's key, which means it changes and cannot be calculated in any reasonable manner

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    When I do a read the key value is "32;JgAAAACLAQAAAAJ7BjEAMAA2ADAAMAAx6;7908161;10;PurchLines4;44;JwAAAACLAQAAAAJ7BjEAMAA2ADAAMAAxAAAAAIcQJw==6;7908180;44;JwAAAACLAQAAAAJ7BjEAMAA2ADAAMAAxAAAAAIcgTg==6;7928780;44;JwAAAACLAQAAAAJ7BjEAMAA2ADAAMAAxAAAAAIcwdQ==6;8242710;44;JwAAAACLAQAAAAJ7BjEAMAA2ADAAMAAxAAAAAIdAnA==6;8242780;"

    It is appending the line's key for each line too. This doesn't seem like the "document type","document no." key that you mention. What am I missing here?

  • Suggested answer
    keoma Profile Picture
    keoma 32,671 on at
    RE: Web service: Add line to PO

    as i wrote the standard way is loading the PO in the client app via webservice using the read(key) function. the key is always the primary key of the table, for the PO it is "document type","document no.". then add a new line using the lines property. the GetRecIdFromKey function is not the best idea to get a record, because the needed key is not available.

    other solutions need customizations, e.g. setting the fields document type, document no. in page 54 to editable

    or use page 518 and set the whole page to editable.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    We're looking for a solution that would not require customizing Business Central at all. Are you saying then that this is not possible with the existing web services?

  • Suggested answer
    keoma Profile Picture
    keoma 32,671 on at
    RE: Web service: Add line to PO

    then create a query based on table purchase line, add only the needed fields.

    publish the query and use in your client app.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    Franz, that was the first approach we tried but we won't have the key available, so we want to update based solely on the PO Number

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    Ideally I'd like to use standard pages/services as this is part of an ISV solution and we don't want to ask the customer to customize their environment directly

  • Suggested answer
    keoma Profile Picture
    keoma 32,671 on at
    RE: Web service: Add line to PO

    you can work with the published purchase order page. the webservice has then a lines property, where you can add your line and update/save the PO.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web service: Add line to PO

    The field is read only in the Page 54. That's why you can't update it from Web Service.

    Out of the box BC API only have Purchase Invoice. I think you have few options:

    1. Add another "Document No." field in page 54 and make it editable but not visible

    2. Create new API page based on existing Purchase Invoice lines API

    docs.microsoft.com/.../dynamics_purchaseinvoiceline

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans