Getting Record from FORM.RUNMODAL without LookupOK

stefan.karnelstefan.karnel Member Posts: 11
Hello!

Does anyone know how to get the actual record of the new form if there
is no LookupOK button in the new form.

Code:
...
FORM.RUNMODAL(AlternativeFormID,Rec);
ActualRecord = Rec;
...


Best regards,
Stefan

Answers

  • bvbeekbvbeek Member Posts: 32
    Hello!

    Does anyone know how to get the actual record of the new form if there
    is no LookupOK button in the new form.

    Code:
    ...
    FORM.RUNMODAL(AlternativeFormID,Rec);
    ActualRecord = Rec;
    ...


    Best regards,
    Stefan

    Is this what you need?

    CLEAR(Form variable);
    Form variable.LOOKUPMODE(TRUE);
    IF Form variable.RUNMODAL = ACTION::LookupOK THEN BEGIN
    Form variable.GETRECORD(Form rec);
    NewRec := Form rec;
    END;
    Yours,
    Bart van Beek
    Boltrics Professionals B.V. | www.boltrics.nl
    Nekovri Dynamics | 3PL Dynamics
  • awarnawarn Member Posts: 261
    Hi,

    To be clear, when you use a list form and put the line:

    Form variable.LOOKUPMODE(TRUE);

    It puts the form into Lookupmode, and if there is an OK button on the form pressing it returns LookupOK = true to the code.

    -awar
  • stefan.karnelstefan.karnel Member Posts: 11
    The answer with the form variable does not fit my needs.
    The form which is called should be configurable. That means I only know the form no. and can not define a variable for this form.

    The record in the call

    FORM.RUNMODAL(FormID, Rec)

    seams only to be set if someone uses the LookupOK button.

    Does anyone know if there is a workaround?

    Regards,
    Stefan
  • ebsoftebsoft Member Posts: 81
    The answer with the form variable does not fit my needs.
    The form which is called should be configurable. That means I only know the form no. and can not define a variable for this form.

    The record in the call

    FORM.RUNMODAL(FormID, Rec)

    seams only to be set if someone uses the LookupOK button.

    Does anyone know if there is a workaround?

    Regards,
    Stefan

    Just to know..
    why can't you use LookupOk button? It has an invalide appearence action, so if you call the form for other purposes... you will not see the LookupOk button!

    Regards,
    Federico
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
  • awarnawarn Member Posts: 261
    If you want to run different forms and do different code based on the form / variable, then you will need to run the form using a different variable for each case, and return the value using variable.GETRECORD.

    What is the situation that you need to dynamically get different variables from differnet forms?

    -awar
  • stefan.karnelstefan.karnel Member Posts: 11
    The goal of the topic is to setup different form for different users for example for the sales order.

    Some users do not need the whole functionality therefor the sales order form for them should be reduced to a minimum.

    When I open the standard form I set the form invisible and want to open the other form. It works well, the only problem I have is that the standard form doesn't save the last viewed record of the other form.

    Stefan
  • McClaneMcClane Member Posts: 40
    Add to your forms a function to return the value you want to get, something like "GiveReturnValue". Code is simple like that:
    exit("Document No."); (for example, don't forget to define the Return Value)

    then define your different forms as variables, e.g. testform1, and use this code in the Object that calls the forms:
    clear(testform1);
    testform1.SetRecord(YourRecord);
    testform1.runmodal;
    YourValue:=testform1.GiveReturnValue;

    the same for testform2 .. testformXY, and you get what you want.
  • stefan.karnelstefan.karnel Member Posts: 11
    To clearify:

    ...
    FORM.RUNMODAL(50010,RecordOfInterest);
    ...

    I found out that the Variable RecordOfInterest is only set to the current record of the form if the ACTION is LookupOK.

    Is there a possibility to set the return action of a form in OnCloseForm to fix the problem?

    I don't want to write a codeunit which has all forms of the customer range as defined vars.
  • IngEolRuinIngEolRuin Member Posts: 23
    The point was if you issue a FORM.RUNMODAL and you have NO Lookupbutton (and therefore cannot click it) the supplied "Rec" is not changed.

    Example:

    Rec = Table 18
    Form = Form 22 - Customer List

    Code:
    Form.RUNMODAL(21, Rec)
    

    Case 1:
    Step 1: Use clicks "OK" , Form closes
    Result: "Rec" is updated

    Case 2:
    Step 1: just scroll around
    Step 2: Close Form
    Result: "Rec" is NOT updated

    If you now substitute Form 22 by Form 21 (Customer Card) you can never reach Case 1 as theres no OK button on the Customer Card ...

    So summarizing the question is:

    Can some C A/L Fu be applied to pursuade the NAV client to update the calling Rec when the form closes in case you happen to have no OK button on the form ?


    And adding functions to (all the 2000+) forms in NAV is cheating :)
    =(there is no question that cannot be used if we use our brain)=
  • McClaneMcClane Member Posts: 40
    if there isa way, i don't know. ](*,)

    btw, adding code to the calls of all the 2000+ forms seems to me cheating, too ;)
  • ajhvdbajhvdb Member Posts: 672
    When I open the standard form I set the form invisible and want to open the other form. It works well, the only problem I have is that the standard form doesn't save the last viewed record of the other form.

    Stefan

    Why not do a saverecord key in the other-form close event (to a singleinstance codeunit)

    and

    in the standard-form get this value back (from the singleinstance codeunit)

    and

    do a rec.get
  • IngEolRuinIngEolRuin Member Posts: 23
    ajhvdb wrote:
    When I open the standard form I set the form invisible and want to open the other form. It works well, the only problem I have is that the standard form doesn't save the last viewed record of the other form.

    Stefan

    Why not do a saverecord key in the other-form close event (to a singleinstance codeunit)

    %SNIP%


    "And adding functions to (all the 2000+) forms in NAV is cheating" ? [-X
    =(there is no question that cannot be used if we use our brain)=
  • ajhvdbajhvdb Member Posts: 672
    This wasn't a requirement. :-s The topic poster is already modifying a standard form.
  • IngEolRuinIngEolRuin Member Posts: 23
    ajhvdb wrote:
    This wasn't a requirement. :-s The topic poster is already modifying a standard form.

    You are definitely right.

    But if you want to do this generally (= for all forms) it creates bad karma to add one function/form ...

    And if you take the original code into account
    ...
    FORM.RUNMODAL(AlternativeFormID,Rec);
    ActualRecord = Rec;
    ...
    

    If you had to modify the form with ID = AlternativeFormID it will be hell of a job if you say you want to realize this for any form.

    But I guess we wait for Stefan 8-[
    =(there is no question that cannot be used if we use our brain)=
  • stefan.karnelstefan.karnel Member Posts: 11
    Hello ajhvdb!

    Thanks for your hint.
    I added the following code to the new form:
    Form - OnCloseForm()
    CurrForm.SAVERECORD;
    

    And I also set in the calling codeunit
    SingleInstance = Yes
    

    but it doesn't work.

    What is wrong?

    Btw. it doesn't matter that there is a change in the form because the form is new anyway.

    Regards,
    Stefan
  • ajhvdbajhvdb Member Posts: 672
    Sorry, but your code is dangerous. :shock: Look in to the How To section for an example of saving values.
  • stefan.karnelstefan.karnel Member Posts: 11
    Sorry ajhvdb!

    Now I understood.
    You need a single instance codeunit which saves the record of the new form and with this codeunit you can read the record in the other form.

    It seams to work great.

    Thanks a lot!
  • stefan.karnelstefan.karnel Member Posts: 11
    Hi to all!

    This is the solution:

    In the new form:
    Form - OnCloseForm()
    MyRecRef.GETTABLE(Rec);
    AltFormMgt.SetRecord(MyRecRef);
    

    In the single instance codeunit AltFormMgt:

    Function to set the record:
    SetRecord(VAR ActualRecRef : RecordRef)
    GlobalRecRef := ActualRecRef;
    GlobalIsSet := TRUE;
    

    Function to set the record:
    GetRecord(VAR ActualRecRef : RecordRef)
    ActualRecRef := GlobalRecRef;
    
    This function can be called to set the record of the old form.

    Thanks to the community to help me to find the solution.

    Regards,
    Stefan
Sign In or Register to comment.