Creating sales header ignore dimension code

galmokgalmok Member Posts: 44
When I create orders in a dataport import, I use this to create sales headers:

SalesHeader.INIT;
SalesHeader."No.":='';
SalesHeader.VALIDATE("No.");
SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order);
SalesHeader.VALIDATE("Sell-to Customer No.",impNo);
SalesHeader.VALIDATE("External Document No.",impExternalDocumentNumber);
SalesHeader.VALIDATE("Shortcut Dimension 1 Code",'SOMECODE');
SalesHeader.INSERT(TRUE);

impNo and impExternalDocumentNumber are set to the right values, but the Shortcut Dimension 1 Code is not inserted. I also don't get any error. The VALIDATE just silently fails. Everything else seems to work just fine. The sales header is created with the required information except for the Dimension code (which does exist).

I am obviously missing something, but what? :-)

Answers

  • kinekine Member Posts: 12,562
    To be as close as possible to manual data entering the correct insert procedure is this:
    SalesHeader.INIT;
    SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order);
    SalesHeader."No.":='';
    SalesHeader.VALIDATE("No.");
    SalesHeader.INSERT(True);  //Insert the record into table
    SalesHeader.VALIDATE("Sell-to Customer No.",impNo);
    SalesHeader.VALIDATE("External Document No.",impExternalDocumentNumber);
    SalesHeader.VALIDATE("Shortcut Dimension 1 Code",'SOMECODE');
    SalesHeader.MODIFY(TRUE); //modify it
    

    When the dimensions are processed, the header must be inserted into DB already, because the dimension entries must be created and connected to this record.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • matttraxmatttrax Member Posts: 2,309
    Your code looks pretty standard and correct.

    My thoughts would be to check the OnValidate trigger for the Dimension Code in the Sales Header. Maybe there was a modification to it that you have forgotten or don't know about.

    Check the document dimension table. I usually see it the other way around, where the dimension is displayed on the header and is not in the document dimension table, but I suppose it could be this way.

    Try putting a CONFIRM after the VALIDATE, CONFIRM('%1', TRUE, SalesHeader."Shortcut Dimension 1 Code"); See if it is coming back set correctly from the validate trigger.

    Then put one after the insert. Maybe something in the insert trigger is changing the value.

    Hope those help. Good luck.
  • galmokgalmok Member Posts: 44
    Thank you, kine. I already suspected that it didn't get the order of the fields quite right but just couldn't see the problem. Your suggestion worked just fine. :-)
  • kinekine Member Posts: 12,562
    You are welcome. If the problem is solved, please, add [solved] prefix into your first post subject. Thanks.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.