web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Web service: Add line to PO

(0) ShareShare
ReportReport
Posted on by

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?

I have the same question (0)
  • Community Member Profile Picture
    on at

    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

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    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
    on at

    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

  • Community Member Profile Picture
    on at

    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

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    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
    on at

    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
    32,729 on at

    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
    on at

    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
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,606

#2
YUN ZHU Profile Picture

YUN ZHU 931 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans