Running form from a function

I am working on a modification for a client. It is in the Quotes form. If the user does not know the ship-to code to enter for a quote (in the shipping tab) they will just fill in the ship-to address details in the quote header. Later they may want to create a new ship-to code for the address they entered on the quote, at which time they will press a menu button(newly created) and the form will open a window asking user for the new ship-to code. For this I’m using a dialog box. then menu button’s OnPush trigger has the code: CreateNewCode.CreateNewShipTo(Rec); COMMIT; IF “Ship-to Code” <> ‘’ THEN VALIDATE(“Ship-to Code”); In the above code CreateNewShipTo is a function in the codeunit CreateNewCode. The CA/L code in this function is: Window.OPEN(‘Enter Ship-to Code:#1##########’); Ok := TRUE; REPEAT Window.INPUT(1,ShipTo); IF ShipToRec.GET(ShipTo) THEN BEGIN MESSAGE(‘This code already exists’); Ok := FALSE; EXIT; END; UNTIL Ok = TRUE; Window.CLOSE; IF ShipTo = ‘’ THEN EXIT; ShipToRec.INIT; ShipToRec.“Customer No.” := SalesHeader.“Sell-to Customer No.”; ShipToRec.Code := ShipTo; ShipToRec.Name := SalesHeader.“Ship-to Name”; ShipToRec.“Name 2” := SalesHeader.“Ship-to Name 2”; ShipToRec.Address := SalesHeader.“Ship-to Address”; ShipToRec.“Address 2” := SalesHeader.“Ship-to Address 2”; ShipToRec.“Address 3” := SalesHeader.“Ship-to Address 3”; ShipToRec.City := SalesHeader.“Ship-to City”; ShipToRec.State := SalesHeader.“Ship-to State”; ShipToRec.“ZIP Code” := SalesHeader.“Ship-to ZIP Code”; ShipToRec.Contact := SalesHeader.“Ship-to Contact”; ShipToRec.“Shipment Method Code” := SalesHeader.“Shipment Method Code”; ShipToRec.“Location Code” := SalesHeader.“Location Code”; ShipToRec.INSERT(); FORM.RUN(300,ShipToRec); SalesHeader.VALIDATE(“Ship-to Code”, ShipTo); SalesHeader.MODIFY; COMMIT; In the above code, SalesHeader is the parameter received by the function and ShipTo and ShipToRec are local variables. The code will create a new record in the Ship-to address table with details from the Quotes Header and open the ship-to address card so that the user can enter more details like Location Code, etc. When user closes the card, control returns to the Quotes form but the additional info entered in the ship-to card(loactio, etc) is not stored in the SalesHeader table though I VALIDATE the Ship-to Code field of the Sales Header table after the statement FORM.RUN(300,ShipToRec); I ran in debug mode and found that this statement is executed after the VALIDATE statement though in the code, it comes before VALIDATE. Can someone explain why this happens and give me a solution? Thanks. Pari Somasundaram

Hi, put some code into the OnAfterGetReccord-Trigger of the form 300 and then debug again. You will see that Navision runs the form before the validate. It is just a problem of when Navision shows you the form-window. Micha

quote:


Originally posted by Micha: Hi, put some code into the OnAfterGetReccord-Trigger of the form 300 and then debug again. You will see that Navision runs the form before the validate. It is just a problem of when Navision shows you the form-window. Micha


Thanks Micha. My requirement is that when the form 300 (Ship-to Address card) comes up I will enter details like Location Code and these details need to be passed back to the Quote Header. How can I accomplish this? Right now the form is presented to user AFTER the validation of quote header’s Ship-to Code field. The form needs to present itself to user before the VALIDATE function is run for the quote header’s Ship-to Code. Thanks. Pari.

Hi Paris, you can use form.runmodal to run the form and make the system wait for the input. The problem is however that you cannot use form.runmodal when you have begun write transactions. This will give the largest error message in Navision :slight_smile: You will have to restructure your code in order not to write into the database before the runmodal. You could consider making the Ship-to record that you show in the form a temporary record. I think you can make an insert in a temp table and use runmodal in the same transaction, but I am not sure.