I’m trying to add a Business Central [Sales Line] child record to a [Sales Header] parent invoice record in a C# OData program. I know the header record exists because the program has just created it & I can see it in BC, but when I try to add the child record using the binding Document No: 102206 I get an error (see below) that indicates it can’t see the header record.
The field Document No. of table Sales Line contains a value (102206) that cannot be found in the related table (Sales Header).
Here’s a clip of the code:-
ReferenceBC.NAV.APISalesLine lobjUSL = ReferenceBC.NAV.APISalesLine.CreateAPISalesLine(“Invoice”, “102206”, 10000);
// lobjPSL is a Sales Invoice Line object (Posted)
// lobjUSL is a Sales Invoice Line object (Unposted)
// gobjDSC is of type Microsoft.OData.Client.DataServiceContext
// populate properties
lobjUSL.Property1 = lobjPSL.Property1;
lobjUSL.Property2 = lobjPSL.Property2;
// etc…
gobjDSC.AddToAPISalesLine(lobjUSL);
gobjDSC.SaveChanges(SaveChangesOptions.None); // Error
Any thoughts?