Write code to open a form

Hello all,

I am new in Nav, how to let the code open “sales comment sheet” after shipment date was updated. The same result like you click sales comment button at Sales Order. So the system can open that form to let user put comments in.

I went to Sales header table → Shipment Date OnValidate() and put the Code at bottom SalesCommentLineForm.RUN. Nav opens that form but give me non filtered record. So how do I realize the function like the button’s RunFormLink? Am I going to the right place?

http://msdn.microsoft.com/en-us/library/dd339052.aspx

Of course you need to tell the form which records to show.
What you need to “simulate” by code is the same action that you do manually in the Form to limit the records:
You would open the form and click Ctrl+F7 and set a filter to the relevant fields (“Document Type” = Order, “No.” = Number of the order you are interested in).

So first action would be to declare a variable of the type record with the sub type “Sales Comment Line”.
Then you would - just before your SalesCommentLineForm.RUN - apply a filter to the record variable:

SalesCommentLine.SETRANGE(“Document Type”, SalesCommentLine.“Document Type”::Order);
SalesCommentLine.SETRANGE(“No.”, Rec.“No.”);

Next would be to hand over that filtered view of the table to the form you defined already:

SalesCommentLineForm.SETTABLEVIEW(SalesCommentLine);

When you now call the form with RUN or RUNMODAL you will just see the records you are interested in.

Thank you, tried that, works perfect.[:D]