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?