How do I initialize a record using C/SIDE?

josephdeweyjosephdewey 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?
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

Comments

  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • josephdeweyjosephdewey Member Posts: 87
    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 User
  • kinekine Member Posts: 12,562
    You are welcome!
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.