简体   繁体   English

在Navision中通过引用运行代码单元

[英]Running a codeunit by reference in Navision

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. XXXX代表生产订单号,但是您看到有人对其进行了硬编码。 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. 我尝试执行SetRANGE例程或直接调用codeunit.run方法,到目前为止还算不上运气。 Help!! 救命!!

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. 然后,您可以在OnRun函数中引用作为Rec传递给codeunit.run的记录。

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. SetRange在传递的变量上是不够的,因为它仅过滤但不选择记录。 You will not need the ProdOrderLine.GET within OnRun, if I understand your problem correctly. 如果我正确理解了您的问题,则在OnRun中不需要ProdOrderLine.GET。 Just call ExecuteFunction(Rec). 只需调用ExecuteFunction(Rec)。

You don't mention version numbers or what the ExecuteFunction function does, but give this a try. 您没有提及版本号或ExecuteFunction函数的功能,但可以尝试一下。

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 您可以在以下位置找到更多信息: https : //msdn.microsoft.com/en-us/library/dd301214 ( v=nav.90) .aspxhttps://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. 自从为Navision开发以来已经有几年了,我再也没有测试的方法了。 Hopefully this will point you in the correct direction, and I haven't forgotten anything critical. 希望这会为您指明正确的方向,而我也没有忘记任何重要的事情。

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. 根据生产订单行表的主键是否实际上是[Status],[Order No。],[Line No.],您将需要使用FIND('-')或FINDSET,具体取决于哪个版本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: 无论如何,我都会将其写为条件语句,除非您希望过滤器结果为0行,则将错误消息返回到UI:

 IF ProdOrderLine.GET(Status,"Order No.", "Line No.") THEN
   ExecuteFunction(ProdOrderLine);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM