Calling Function in subform

tompynation
tompynation Member Posts: 398
Hi, i've added a new subform to the item card.

In this subform i have created the following method:

SetItemCode(ItemCode : Code[20])
gv_ItemCode := ItemCode;



This subform also contains a button with the following push action:

<Control1000000007> - OnPush()
MESSAGE('Item Code: ' + FORMAT(gv_ItemCode));

The gv_ItemCode is a global variable...


Then in Item Card form, in the onaftergetrecord i call the SetItemCode
and pass Rec."No." to it...

If i follow in debugger the gv_ItemCode gets filled up with the Rec."No."

When i then go to the tabpage with my new subform on and press the button, the gv_ItemCode is back empty ](*,)

Why is this?

Answers

  • tompynation
    tompynation Member Posts: 398
    i call the SetItemCode in the OnAfterGetRecord form the Item card like this:

    gv_EenhedenSubForm.SetItemCode("No.");

    gv_EenhedenSubForm is a global variable of type Form
  • garak
    garak Member Posts: 3,263
    Do you call the function from your Subform in your Form - OnAfterGetRecord() Trigger?
    Do you make it right, it works too!
  • garak
    garak Member Posts: 3,263
    MainForm:
    Form - OnAfterGetRecord()
    CurrForm.SubForm.FORM.SetItemNo("No.");

    SubForm:
    SetItemNo(LocItemNo : Code[20])
    GlobItemNo := LocItemNo;

    Button on Subform
    <Control1119402007> - OnPush()
    MESSAGE(GlobItemNo);
    Do you make it right, it works too!
  • NaviDev
    NaviDev Member Posts: 365
    If I am not mistaken, your problem is retrieving the Item number from the sub form..? If this is the case, then change the property name of your subform and call the GETRECORD function in the subform in your button. Something like this code
    CurrForm.YourSubFormName.GETRECORD(RetrieveRecord);
    MESSAGE("RetrieveRecord.No.");
    


    for more details for the GETRECORD function. Please read the help.
    Navision noob....
  • tompynation
    tompynation Member Posts: 398
    No thats not what i mean...

    I want to have the Item rec inside my subform

    I dont want to have the record from my subform inside the Item Card Form
  • NaviDev
    NaviDev Member Posts: 365
    Pass the record by reference. To do this just mark the Var field in your function parameters.
    Navision noob....
  • tompynation
    tompynation Member Posts: 398
    CurrForm.SubForm.FORM.SetItemNo("No.");


    This was what i needed... i was unable to call the function of my named subform cause i allways tried like CurrForm.SubForm.SetItemNo("No.")
    which was not valid off course

    I didnt know you had to add .FORM between it

    Anyway, works fine now. Thanks for the help O:)
  • garak
    garak Member Posts: 3,263
    Please.

    Please write [solved] infront of you subject (first post)
    Do you make it right, it works too!
  • GRUBBYFANS
    GRUBBYFANS Member Posts: 154
    hi,this is my code ,it is successful,i think it can help you,

    my subform name is :salelines,and I add a function example
    example()
    message('it is ok');

    main form I add button I call it
    currform.saleline.form.example;