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

Failing to add a row to BC table

(0) ShareShare
ReportReport
Posted on by 891
Using Microsoft PowerApps, I'm trying to add a row to a child BC table called "Service Lines" that has a relationship to a parent table "Service Item Lines" which in turn has a relationship to its parent table: "Service Order". They are joined by two fields: Document_Type and Document_No. There is also an auto-generated field called Line_No that increments by 10000 for each "Service Line".
When I use the SubmitForm command I get the error: The requested operation is invalid. Server Response: Dynamics NAV: Request failed (404): The remote server returned an error: (404) Not Found. (The field 'Service Item Line No.' of table 'Service Line' contains a value (10000) that cannot be found in the related table (Service Item Line).). However, when I look in Business Central there is clearly a record in the 'Service Item Line' table with the 'Line No.' value: 10000.
When I use the Patch command I get the error: "Key fields are generated by the server and can't be specified.". But I have to specify them so that they are bound to the parent?!
I tried omitting the key fields and it complained that they were missing. So it's not happy whether the key fields are there or not.
I also tried using Visual Studio 2017, C# and a Connected Service (see code below). But I get the error: "BadRequest: "Control 'VAT %' is read-only."
// Instantiate
Bell.NAV.Service_Lines lobjSL = Bell.NAV.Service_Lines.CreateService_Lines("Order", "SO000001", 10000);
// Populate properties
lobjSL.Type = "Item";
lobjSL.No = "DXL-20SN3";
lobjSL.Description = "2000W Xenon Lamp, Digital Cinema";
lobjSL.Location_Code = "BELLMAIN";
lobjSL.Unit_of_Measure_Code = "EACH";
lobjSL.Quantity = 1;
// Add the row via context object
gobjDSC_Bell.AddToService_Lines(lobjSL);
gobjDSC_Bell.SaveChanges(); // ERROR
What am I doing wrong? What's the secret to adding a row to a table that has a relationship to a parent table? Or is it NOT possible?
Any help you can provide will be greatly appreciated?
I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    This is possible, I suggest to create a custom API page. the "readonly" error you're receiving is because you're using a published page and the control is readonly on that page.

  • Nick Webb Profile Picture
    891 on at

    Thanks so much for your helpful response. I've got it working in C# now, but what about PowerApps? Is it correct to say that any database transaction you can perform in C# with OData, you should be able to do in PowerApps?

  • Nick Webb Profile Picture
    891 on at

    So, using the same custom API page as previously, successfully employed in Visual Studio I attempted a SubmitForm & a Patch with no success. With Patch I get: LineNo: The specified column is generated by the server and can't be specified. But, I think I need to specify it. I did in .NET. This is the field that needs to increment by 10000 as mentioned above. I've come up with a formula in PowerApps to calculate the next number: Max(Filter(API_Service_Line, DocumentNo = curSONum), LineNo) + 10000.

    SubmitForm gives the error: The requested operation is invalid. Server Response: Dynamics NAV: Request failed: The remote server returned an error: (400) Bad Request. (Document No. must have a value in Service Line: Document Type=Quote. Document No.=, Line No.=0., It cannot be zero or empty.)

    It's like it's lost all the values on the form?

    Thanks in advance for your help.

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,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 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