Why record level variable is empty?

yukonyukon Member Posts: 361
Hi Expert,

I declared variable in Sales Line table. But that variable is empty after another form close. How to solve it ? Please let me know.

 g_fnSetValue(var p_code); //         At Item List
      g_codItemCode := p_code;


// Sales Line (Record)
  l_recItem.RESET;
  g_frmItemList.SETRECORD(l_recItem);
  g_frmItemList.LOOKUPMODE(TRUE);
  IF g_frmItemList.RUNMODAL = ACTION::LookupOK THEN
    g_frmItemList.GETRECORD(l_recItem);
  VALIDATE("No.",l_recItem."No.");
  g_frmItemList.g_fnSetValue(g_ItemCode);
  MESSAGE('%1',g_ItemCode);

The variable is empty when "Validate" trigger and when i click new line. Why? How can i get data?
Make Simple & Easy

Comments

  • kinekine Member Posts: 12,562
    1) From where is this code called?
    2) Which record is empty?
    3) All depends on context. because sometime you need to call modify, sometime it will be saved automatically etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    g_fnSetValue(var p_code); //         At Item List
          g_codItemCode := p_code;
    
    
    // Sales Line (Record)
      l_recItem.RESET;
      g_frmItemList.SETRECORD(l_recItem);
      g_frmItemList.LOOKUPMODE(TRUE);
      IF g_frmItemList.RUNMODAL = ACTION::LookupOK THEN
        g_frmItemList.GETRECORD(l_recItem);
      VALIDATE("No.",l_recItem."No.");
      g_frmItemList.g_fnSetValue(g_ItemCode);
      MESSAGE('%1',g_ItemCode);
    

    1. Is the function g_fnSetValue() a function in form 31 Item List:?:
    2. You call this function with
    g_frmItemList.g_fnSetValue(g_ItemCode);
      MESSAGE('%1',g_ItemCode);
    
    , but where you set the g_ItemCode :?: So, your message will ever be empty.
    3. What is the reason why you do this. What do you want to do ?
    Do you make it right, it works too!
  • yukonyukon Member Posts: 361
    1. Is the function g_fnSetValue() a function in form 31 Item List:?:
    ---- Yeah! i used Form 31. And Create New Function.
    ---- g_fnSetValue(ref: paremeter g_ItemCode);
    2. You call this function with ----
    , but where you set the g_ItemCode :?: So, your message will ever be empty.
    --- g_ItemCode Declare at Sales Line Table.
    --- g_frmItemList.g_fnSetValue(g_ItemCode); Write At Sales Line "Item No" Validate
    --- MESSAGE('%1',g_ItemCode); will show after validate.
    --- When i create new line that variable is empty.
    3. What is the reason why you do this. What do you want to do ?
    --- I want to save that variable because of Item no is default filter with that value when i select new line (item no).

    Sorry for my reply is too late.

    Best Regards,
    Yukon
    Make Simple & Easy
  • kinekine Member Posts: 12,562
    --- When i create new line that variable is empty.

    Yes, it is, because the form is using "new" instance of Rec when creating line, it means all variables on the table are cleared...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • yukonyukon Member Posts: 361
    Hi kine,

    Thx... We don't choice for that ](*,)


    Regards,
    Yukon
    Make Simple & Easy
  • kinekine Member Posts: 12,562
    If you want to fill the field by the value from filter automatically to have the new line "within" the filters, you can use PopulateAllFields property on the form. This will force NAV to fill the fields by the filter values if the filter is filtering on one exact value (this works automatically for primary key fields, this property extends the functionality to all fields).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • yukonyukon Member Posts: 361
    Hi Kine,
    If you want to fill the field by the value from filter automatically to have the new line "within" the filters, you can use PopulateAllFields property on the form. This will force NAV to fill the fields by the filter values if the filter is filtering on one exact value (this works automatically for primary key fields, this property extends the functionality to all fields).

    I set "Yes" at PopulateAllFields in item list (Form 31). And I go back to Sales Order.
    1st I Filter(F7) By Item Category Code = 'PUMP', selected one item no (1000). And then i go to next line Press Item No button. But item list show all. I want to get/see previous data with Filter Item Category Code = 'PUMP' only.

    Is it possible with code?

    Regards,
    Yukon
    Make Simple & Easy
  • kinekine Member Posts: 12,562
    Ah, you want to filter the selection... sorry, do not take into account my previous post, it is about something different...

    There is no standard way how to do that. The Lookup form will not save your filters between two lookups. You will need somehow change the OnLookup trigger to save the value,but you need to save it not only in global variable of the Rec, but e.g. in singleinstance codeunit (or you need to change the OnLookup on the form and save the filters in form global variable, but this will work only for the specified form...).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • yukonyukon Member Posts: 361
    Hi Kine,


    That right ...! I accept your suggestion and i also did it. But we can declare at form level. If i write form level, i need to write onlook trigger of all forms. So but i don't have choice for that .... ](*,)


    Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.