Hi everyone
I’m a noobie in Nav, I’m trying to use a codeunit from a report.
The codeunit needs to fill a blob field in the current record that the report is working with on the ‘Sales Header’ table.
The problem is (this may sound a little ignorant) that as I understand it, the codeunit has a limited scope and doesn’t know what record the report is working with.
I need a way to pass a parameter to the function in the codeunit that makes it aware of the current record that the calling report is set to.
I have successfully filled-up the blob (for testing purposes) to the very last record in the table using SalesHeader.FINDLAST in the codeunit.
This command successfully points to the last record on the table and then the function goes on and fills-up the blob correctly.
My question is: How can I specify the actual record that I want to work with on the codeunit?
Thank you!
hi,
create a function in the codunit. do that in the global variables, tab “functions”. only write the name of the function, e.g. “ChangeSalesHeader”, into the first row. then click on button locals. there in the first tab “parameters” write “salesHeaderPar” into the name column of the first row, type “rec”, subtype “sales header”. activate the VAR field selection (first column). this effects that the sales header record you pass is the same record you get back when leaving the function call in the report. after that leave the globals variables dialog using ESC key and write your code under the new function trigger. after that create a new variable in your report with type codeunit and subtype “”. write the function call to the needed position like .ChangeSalesHeader(salesHeaderLoc).
regards
Thank you so much for your answer
I followed your instructions and the only question remaining is:
From the report when I use the NameOfMyCU.ChangeSalesHeader(salesHeaderLoc), what do I actually use for the salesHeaderLoc parameter?
hi,
this was only an example. it depends on what you want to do.
have a look at the nav standard reports, e.g. 205 order confirmation.
this report is based in first place on “sales header”, means the first dataitem is of type “sales header”. and there you have your answer. “sales header” is in the report also the name of record to use.
for example in the (report-)trigger “Sales Header - OnAfterGetRecord” you can set your function call and use the record name “Sales Header” as param: “YourCU.ChangeSalesHeader(“Sales Header”)” .
regards
addition. if you want to use an other record, you can also define a local variable for the selected trigger, e.g. on aftergetrecord, give the local variable a name salesHeaderLoc, type record, subtype “sales header”. after that you can also use that local variable as a param. for your (CU-) fcuntion. regards
It worked, thanks a lot !!!