Options

Filling fields

lucianaluciana Member Posts: 43
Hi!

How can I fill automatically fill a field?
E.g.
I have a subform with fields Number and Description that refers to a table.
When I insert a number in the field Number and press "Enter" Button, in the field "Description" I would have the text associated with that number.
I tried to look at the cronus tables and forms but I haven't understood how that works.
Thank you.

Luciana

Comments

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    If you take Purchase Line table(39), when you enter item No, we get description automatically
    for this code is written in onvalidate trigger of "No." field
    Type::Item:
        BEGIN
          GetItem;
          GetGLSetup;
          Item.TESTFIELD(Blocked,FALSE);
          Item.TESTFIELD("Inventory Posting Group");
          Item.TESTFIELD("Gen. Prod. Posting Group");
    
          "Posting Group" := Item."Inventory Posting Group";
          Description := Item.Description;
          "Description 2" := Item."Description 2";
    
  • Options
    lucianaluciana Member Posts: 43
    I don't understand.

    I take code similar to table 39 (Purchase Line).

    I my table I wrote on OnValidate Trigger in Nro field:

    IF tArticoli.Nro <> "Nro Articolo" THEN
      tArticoli.GET("Nro Articolo");
     Descrizione2 := tArticoli.Descrizione;
    

    where tArticoli is the table in which I have Nro and Descrizione.
    Nro Articolo is the field in form that I insert manually, Descrizione2 is the field in forul that have to be populated automatically.

    But nothing happens.
    Where am I wrong?
  • Options
    BeliasBelias Member Posts: 2,998
    where to start... :-k

    1. a lot of study :whistle:
    2. the programming language is english, not italian...please use english names for your variables and fields (if possible)
    3. you're setting field descrizione in descrizione2. why?is it correct?is descrizione2 a field or a variable?
    4. Did i mention "a lot of study"? :mrgreen:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    lucianaluciana Member Posts: 43
    Belias wrote:
    where to start... :-k

    1. a lot of study :whistle:
    2. the programming language is english, not italian...please use english names for your variables and fields (if possible)
    3. you're setting field descrizione in descrizione2. why?is it correct?is descrizione2 a field or a variable?
    4. Did i mention "a lot of study"? :mrgreen:

    1. I do what I can :) I'm studying, so I ask in this forum :)
    2. Pardon, I'm doing an exercise in italian so I hae used italian... but I can translate.
    3 Descrizione2 is a text variable, Descrizione is a field in a table
    IF tArticoli.Nro <> "Nro Articolo" THEN
      tArticoli.GET("Nro Articolo");
    Descrizione2 := tArticoli.Descrizione;
    

    translated is:
    IF tItem.Nr <> "Item Nr" THEN
       tItem.GET("Item Nr");
    Description2 := tItem.Description;
    


    In practice I have to do an exercise emulating the purchase oder form.
    So i have an Item table (that's not the Item table standard) with an Item Number and a Description.
    The Purchase form that I've done, has a subform , containing an Order Nr, an Item Nr, a Description and a quantity field.
    When in the subform I select the Item Nr from Item table, in Description field of the subform, I should have the value of Description field of Item Table.

    I tried, as mohana suggested, to do the same thing that is contained in code of tab 39, but I don't retrieve anything automatically.
    I also tried to set a table relation, but nothing.
    I don't understand.

    thanks
    Luciana
  • Options
    BeliasBelias Member Posts: 2,998
    you're doing it wrong: you are showing field nr. and field description in your form, but you've evaluated a variable.

    You have to evaluate
    description := item.description;

    not
    description2 := item.description;

    moreover, if you are still studying the base, you shouldn't work for an actual production process, you can cause a lot of damages to the customer data! ask your boss/senior developer if they can give you a hand.
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    lucianaluciana Member Posts: 43
    but I don't have a real company to work for.
    My boss is giving to me exercises to do to understand how C/AL works. I have only a book about C/AL and there's nothing more of what I know, so I have to ask here questions that make me doubtful.
    :)
    Thank you, now I'm gonna try your solution.

    Luciana
  • Options
    BeliasBelias Member Posts: 2,998
    :-k pretty strange situation, indeed...you should have SOME books and a senior developer to start programming...to use a metaphore (one of david singleton's favourites :) ), you can't drive a car because you googled how to do it. You need books, experience, and a teacher!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    lucianaluciana Member Posts: 43
    exactly.. pretty strange situation... but I can't solve it.

    so, your solution doesn't work for me. uhmmm ...
  • Options
    BeliasBelias Member Posts: 2,998
    i've just read that you put the code in the onvalidate of Nro field of table item....
    Do you know what is Onvalidate trigger? it is when you write something in a field and then hit TAB, or Enter, Or Up or dwn arrows....

    You're inserting the new value of the field in Nro Articolo, but you've coded the onvalidate trigger of item.Nro: obviously that code is not fired because you've to put it in the onvalidate trigger of Nro Articolo, instead.

    But i'm wondering how did you compile the code O.o ...i think there's something messed up with the data structure, too...sorry but if this doesn't work either, i can't help you more, there are too much possible errors :roll:
    Good luck!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    lucianaluciana Member Posts: 43
    I put on OnValidate Item Nr of subform this:
    tItem.RESET;
    tItem.SETRANGE(tItem.Description,"Item Nr");
      IF tItem.FIND('-') THEN
        Description := tItem.Description;
    

    Now I can see the correct value associated to the Item Nr selected.
    It's not automatic, I have to put it in manually (but if I insert the first letter and then I press TAB , it is filled auto).
    Better than nothing.
  • Options
    lucianaluciana Member Posts: 43
    I put on OnValidate Item Nr of subform this:
    tItem.RESET;
    tItem.SETRANGE(tItem.Description,"Item Nr");
      IF tItem.FIND('-') THEN
        Description := tItem.Description;
    

    Now I can see the correct value associated to the Item Nr selected.
    It's not automatic, I have to put it in manually (but if I insert the first letter and then I press TAB , it is filled auto).
    Better than nothing.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    You mean you need to get the Item Nr when you press first letter and TAB?
    Do you have table relation for that field with appropriate table?
  • Options
    SogSog Member Posts: 1,023
    How can I fill automatically fill a field?
    E.g.
    I have a subform with fields Number and Description that refers to a table.
    When I insert a number in the field Number and press "Enter" Button, in the field "Description" I would have the text associated with that number.
    I tried to look at the cronus tables and forms but I haven't understood how that works.
    Thank you.

    Luciana

    your record: item no. and description (and some more fields offcourse)
    your subform: a form based on "your record" records which just shows one (card) or more (list) records.

    if you want to fill in the item no. and have in description the description of the item:
    design table "your record": tablerelation for "item no." is item."no.";
    in the onvalidate trigger in your table for "item no." enter the code mentioned in previous posts.
    Save and compile your table.
    In your form: remove any code in any onvalidate trigger.
    That should do it.

    The problem here is that you're not thinking in NAV right now.
    When you start writing code the first step should always be: where to put my code? aka Define your scope where your code could be handy.
    In this scenario the code should be put in table, because you'll always want that whenever you insert/modify a "your record" record, the description will always initially be the description of the item. If the code is put there, then no matter where in the system you add a record of this type, the description will always initially be the description of the item.
    If you write the code on the form, then only in that form will the description be placed on your record.

    Ask your boss for the C/Side introduction manual. It will help you alot.
    (And welcome to the world of NAV, the longer you stay, the more your feelings will be mixed about this program :) )
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Options
    lucianaluciana Member Posts: 43
    You mean you need to get the Item Nr when you press first letter and TAB?
    Do you have table relation for that field with appropriate table?

    No, I want thaht the field Description is filled automatically when I press TAB on Item Nr.
    Yes I have a table relation for that field.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    luciana wrote:
    tItem.SETRANGE(tItem.Description,"Item Nr");
    

    You should have used
    tItem.SETRANGE("No.","Item Nr");
    
  • Options
    lucianaluciana Member Posts: 43
    luciana wrote:
    tItem.SETRANGE(tItem.Description,"Item Nr");
    

    You should have used
    tItem.SETRANGE("No.","Item Nr");
    

    YEaahhhh it works! :)
    Thank you.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    welcome..

    BTW, move this code to Table OnValidate of Item Nr from form
  • Options
    lucianaluciana Member Posts: 43
    Sog wrote:
    The problem here is that you're not thinking in NAV right now.
    When you start writing code the first step should always be: where to put my code? aka Define your scope where your code could be handy.
    In this scenario the code should be put in table, because you'll always want that whenever you insert/modify a "your record" record, the description will always initially be the description of the item. If the code is put there, then no matter where in the system you add a record of this type, the description will always initially be the description of the item.
    If you write the code on the form, then only in that form will the description be placed on your record.

    Thank you very much for explanations and advices, I'll keep in my mind for next time, they are very very useful :)
    (And welcome to the world of NAV, the longer you stay, the more your feelings will be mixed about this program :) )
    [/quote]
    A lot of feelings: hate, hate and , I've yet said "hate" ? :P
    Seriousely, thank you. I know that these questions are "stupid" but I don't have any guide and no tutor about these things.
    I try to do my best. :)

    Luciana
  • Options
    lucianaluciana Member Posts: 43
    welcome..

    BTW, move this code to Table OnValidate of Item Nr from form

    Done.
    Thanks.
    To everyone.

    And I apologize for my very bad english. Some times I don't know how translate some sentences and I do this literally, so some word, some expression, could be strange or imcomprehensible. Thanks also for understandig :D
Sign In or Register to comment.