MODIFY records using CAL

cedruscedrus Member Posts: 15
Hello,

I'm trying to update the "Shortcut Dimension 2 Code" in the Sales Line table when printing an Order confirmation.
This works using following code:
//RoundLoop, Body (3) - OnPostSection()
IF ("Sales Line"."Shortcut Dimension 2 Code"='') THEN BEGIN
    "Sales Line".VALIDATE("Description 2", "Sales Header"."Salesperson Code");
    "Sales Line".MODIFY;
END;
BUT... this also clears the value of "No." when the item/record in the sales line is a "G/L account" item.
Any ideas?

Kind regards,
Jeroen

Answers

  • ara3nara3n Member Posts: 9,256
    You need to do this code in <Sales Line> dataitem. In trigger OnAfterGetRecord
    Sales Line - OnAfterGetRecord()
    //Start Mod
    IF ("Shortcut Dimension 2 Code"='') THEN BEGIN
        VALIDATE("Description 2", "Sales Header"."Salesperson Code");
        MODIFY(true);
    END; 
    //End Mod
    TempSalesLine := "Sales Line";
    TempSalesLine.INSERT;
    HighestLineNo := "Line No.";
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ErictPErictP Member Posts: 164
    If this is the original report 205 "Order Confirmation" there is in the trigger OnAfterGetRecord from the RoundLoop some code that clears the "No.":
    IF (SalesLine.Type = SalesLine.Type::"G/L Account") AND (NOT ShowInternalInfo) THEN
      "Sales Line"."No." := '';
    
  • cedruscedrus Member Posts: 15
    Thank for the reply Rashed, I originally started out putting the code in the OnAfterGetRecord trigger of the Sales Line data-item, but when it's located there, it doesn't update the table at all, that's why I've put it here:
    //RoundLoop, Body (3) - OnPostSection()
    
    I've tried it again using your code, but the result still remains the same, am I missing something here??

    Regards,
    Jeroen
  • DenSterDenSter Member Posts: 8,305
    You should not put any data manipulation code in any of the section triggers. Those are there to manage the appearance of the report. All your data code should be in the dataitem triggers.

    If all you need to do is update the description 2 field, why not just setting it, without validating the field. So instead of
    VALIDATE("Description 2", "Sales Header"."Salesperson Code"); 
    MODIFY(true);
    
    you do this:
    "Description 2" := "Sales Header"."Salesperson Code"; 
    MODIFY(true);
    
  • cedruscedrus Member Posts: 15
    ara3n, first of all, sorry I called you "Rashed", or should I aplogize to Rashed (was reading one of his posts when I replied)? :)

    And as for you Eric, thank you very much, you've found me the culprit.
    Bedankt,

    Thank you all very much for your input.

    Regards,
    Jeroen
  • cedruscedrus Member Posts: 15
    DenSter,

    Thanks for the info, will do that,

    Regards,
    Jeroen
  • ara3nara3n Member Posts: 9,256
    ara3n = Rashed.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.