two posts at the same time, as you can see I’m quite new in NAV…
I’ve created a function on a form, it only creates a new record, set a few data and then show the form (type Card) with the record I’ve just inserted. The code is like this:
You’re right, it works with COMMIT and RUNMODAL. But I can’t understand why having the same code and same variables on a pair of forms, it works different. For example…
RUNMODAL → I got one form (form1) and with a command open another (form2), the normal way would be that I couldn’t access the form1 while form2 is open. I got the same code in two forms and one doesn’t allow me to select the background form (form1) but the other allows me !!
RUN → same example below (form1, push command → form2). Close form1 and sometimes automatically close form2 too but not another
INSERT and then FORM.RUN runs the form and then continues with the command after the FORM.RUN and the transaction started by INSERT (or before it) is still active. So it is quite unsure what happens.
With INSERT and then COMMIT and then FORM.RUNMODAL. You commit the transaction, then you open the form. And only when you have closed the form, Navision continues with the code after the FORM.RUNMODAL.
The topic of your post mentioned basics, so let me address that.
The fundamental core to these two commands, is connected to how the version principle works, and what COMMIT does.
RUN.FORM or MyForm.RUN
This command basically launches a FORM as a new process. The form runs on its own, and looks at the current Btree to see what Version it is using. Any data changes made in that form are committed following the normal rules of Navision. BUT the task the launched the form has no connection at all to this one, so you can not pass parameters to the form, nor get them back by simple means. If you have ten lines of code, and line 5 is a RUN.FORM command, then the form runs, and control immediately goes back tot eh calling routine, which then continues to run.
RUNMODAL.FORM or MyForm.RUNMODAL
When you run Modal, the system considers the Form as a part of the current transaction. This means that you need to finalize the current transaction (COMMIT the Version) you are on so that the form can open. When the form opens, the calling code stops and waits for you to return control. Navision requires you to put a COMMIT in the code before the form opens. Logically this is unnecessary, since an assumed commit is there anyway when the form Opens, BUT this is required, so that the programmer consciously knows that they are working in a Version that needs to be committed. If there have been no modifications to the current version set, then the commit does not matter. Once the Form is closed by the user, control is passed back to the calling routine, and that routine can use data from the Form.
It is very important that a developer uses the correct caller, AND that they know why they are calling in uncommitted or MODAL.