My overarching question is, "How do I initialize a record using C/SIDE, in exactly the same way that it gets initialized through the application."
The specific thing that happened was: I'm writing an XMLport to import Sales Header, and I'm importing the variables into a temporary table. But, the number series never initialize to the correct values in the temporary table (the fields "Posting No. Series", and "Shipping No. Series").
When I use the code below, those two fields are blank. When I go to the form, and type in a value in the "No." field, and press tab, then the fields are populated.
How do I fix my code so that it functions the exact same way it does if I create the record through the form?
TempHeader.InitRecord;
TempHeader.VALIDATE("Document Type", TempHeader."Document Type"::Order);
TempHeader.VALIDATE("No.", ORDER_NUMBER);
TempHeader.VALIDATE("Sell-to Customer No.", CUST_ID);
I also tried TempHeader.INIT; , but that didn't work either.
Comments
Another thing is, that in client, the primary keys are filled in, than INSERT is done, and after that other fields are filled in and MODIFY done at the end.
It means something like:
BUT!!! NEVER use validation and triggers when working with TEMP tables! It is way to hell!
Do not forget that the code behind could create some new data to different tables, and the tables will reference to record, which doesn't exists in the real table! (like Document Dimensions table referring to your order, which doesn't exists). Thus fill the values to the temp table without validation, at the end of the process, go through the temp and create the resulting records in the real table through using validation and triggers.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Thanks for your kindly advice. Using your information, I was able to solve the problem. I put INSERT(True) on the final insert after I copy the temporary table into the real table, and that fixed everything.
I wasn't ever able to get TempHeader.INSERT(True); to work on an XMLport, though.
Also, I hadn't even considered the effects of Validate on a temporary table. THANK YOU! I'm so glad you gave me this advice before I moved anything to my live system. I'm restructuring my code right now so there are no validates on the temporary table.
Thanks again!
Microsoft Dynamics NAV User
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.