1

I have a codeunit that has the Production Order Line table as the source and the On Run trigger shows these two lines of code:

ProdOrderLine.GET(Status,'xxxx',10000);
ExecuteFunction(ProorderLine);

The XXXX represents the Production Order No. but someone hard coded it in as you can see. How do I call this codeunit else where (say on a form) but by reference depending on which Production Order line I am on? I tried doing the SetRANGE routine or calling the codeunit.run method directly and so far have no luck. Help!!

Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
WSNoob
  • 33
  • 8

2 Answers2

5

Open the codeunit, or a copy of it for testing, in design mode and set the table no. property of the codeunit. Then you can refer to the record passed to codeunit.run as Rec within the OnRun function.

The way you pass in the record varies, but one way is to use this syntax:

Codeunit.RUN(CodeUnitNumber, Record)

SetRange will not be sufficient on the passed in variable because it only filters, but doesn't choose a record. You will not need the ProdOrderLine.GET within OnRun, if I understand your problem correctly. Just call ExecuteFunction(Rec).

You don't mention version numbers or what the ExecuteFunction function does, but give this a try.

You can find more information at: https://msdn.microsoft.com/en-us/library/dd301214(v=nav.90).aspx and https://msdn.microsoft.com/en-us/library/dd355035(v=nav.90).aspx

It's been a few years since I developed for Navision, and I don't have a way of testing anymore. Hopefully this will point you in the correct direction, and I haven't forgotten anything critical.

Kent Weigel
  • 1,168
  • 1
  • 11
  • 16
  • Thank you so much for your help. Yes you did this point out one step I missed when I tried to use rec. I didn't set the table property so I am going to give it a try. – WSNoob Oct 04 '16 at 03:25
1

Depending upon whether or not the primary key for the Production Order Line table is in fact [Status], [Order No.], [Line No.] you would need to use FIND ('-') or FINDSET depending on which version of NAV.

It appears the line no is also hard coded....does this process only concern itself with the first line of the order?

Are you interested in the Order No. Or Document No.?

In any case I would write it as a conditional statement unless you prefer an error message is returned to the UI if the filter results in 0 rows:

 IF ProdOrderLine.GET(Status,"Order No.", "Line No.") THEN
   ExecuteFunction(ProdOrderLine);
Daniel
  • 174
  • 5