Retrieve and insert record

jaro84jaro84 Member Posts: 17
Hi there!

Im new to Nav development and I hope that someone can help me here :)

I want to retrive a record from table 27(Item) where No. equals 1 and save it in a variable.
I have created a variable called SalesLine of type Record and subtype Item where I want to store the retrieved record.

Then I want to insert this record into Form 46(SalesOrderSubForm).

I want this to happen everytime a user creates a new Sales Order.

Hope someone can help me or give me a hint :)

Answers

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    If I understand your question correctly your business case is to create a new sales line with an item.

    This does not work as you expect if I analyse your question correclty.

    You should create a variable of the type Record and subtype Sales Line.

    Then you can create code like this:
    SalesLine.INIT;
    SalesLine."Document No." := 'SOMENO';
    SalesLine."Line No." := 10000;
    SalesLine.INSERT(TRUE);
    SalesLine.VALIDATE("Item No.", 'THEITEM');
    SalesLine.MODIFY(TRUE);
    

    May I humbly suggest this book:

    http://www.packtpub.com/programming-mic ... -2009/book
  • jaro84jaro84 Member Posts: 17
    Thanks for your answer.
    I've tried to your code example a couple of times, but I keep getting errors like:
    The sales header does not exists.
    Identification fields and values: Document Type='Quote',No.='SOMENO'

    This is the code:
    Form - OnBeforePutRecord()

    SalesLine.INIT;
    SalesLine."Document No." := '1';
    SalesLine."No." := '1';
    SalesLine.INSERT(TRUE);
    SalesLine.VALIDATE("Item No.", 'THEITEM');
    SalesLine.MODIFY(TRUE);

    I want to insert item nr 1 into the sales line.
    Of item nr 1 I only want to insert: No., Description, Base Unit of Measure and Unit Price

    What is wrong? :/
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    There is a small typo in my code.
    SalesLine.INIT;
    SalesLine."Document No." := '1';
    SalesLine."Line No." := 10000;
    SalesLine.INSERT(TRUE);
    SalesLine.VALIDATE(Type, Type::Item);
    SalesLine.VALIDATE("No.", '1');
    SalesLine.MODIFY(TRUE);
    

    Sorry.
  • matttraxmatttrax Member Posts: 2,309
    jaro84 wrote:
    I've tried to your code example a couple of times, but I keep getting errors like:
    The sales header does not exists.

    Read through the basic NAV Functional (not development) introduction. You have to know how the application works before you can develop for it. That means you have to know what a header is and what a line is and how they relate to each other.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    matttrax wrote:

    Read through the basic NAV Functional (not development) introduction. You have to know how the application works before you can develop for it. That means you have to know what a header is and what a line is and how they relate to each other.

    Agree. Or some of the Packt books.

    That does not justify my typo though... :?
  • jaro84jaro84 Member Posts: 17
    Thank you for your help and time :)
Sign In or Register to comment.