CLEAR(Form variable);
Form variable.LOOKUPMODE(TRUE);
IF Form variable.RUNMODAL = ACTION::LookupOK THEN BEGIN
Form variable.GETRECORD(Form rec);
NewRec := Form rec;
END;
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.
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
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?
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.
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.
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)=
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)
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)=
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.
Answers
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;
Bart van Beek
Boltrics Professionals B.V. | www.boltrics.nl
Nekovri Dynamics | 3PL Dynamics
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
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
Federico
MBS Specialist since NAV 2.0
My experiences on Linkedin
What is the situation that you need to dynamically get different variables from differnet forms?
-awar
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
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.
...
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.
Example:
Rec = Table 18
Form = Form 22 - Customer List
Code:
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
btw, adding code to the calls of all the 2000+ forms seems to me cheating, too
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
"And adding functions to (all the 2000+) forms in NAV is cheating" ? [-X
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
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-[
Thanks for your hint.
I added the following code to the new form:
And I also set in the calling codeunit
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
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!
This is the solution:
In the new form:
In the single instance codeunit AltFormMgt:
Function to set the record:
Function to set the record: 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