How do I initialize a record using C/SIDE?

josephdewey
Member Posts: 87
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?
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.
Joseph Dewey
Microsoft Dynamics NAV User
Microsoft Dynamics NAV User
0
Comments
-
Problem is, that you are filling the No. field manually, but if you do it in client, it will be taken from no. series and the no. series are filled in.
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:TempHeader.InitRecord; TempHeader.VALIDATE("Document Type", TempHeader."Document Type"::Order); TempHeader.INSERT(True); TempHeader.VALIDATE("Sell-to Customer No.", CUST_ID); TempHeader.MODIFY(True);
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.0 -
Hi Kine,
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!Joseph Dewey
Microsoft Dynamics NAV User0 -
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions