Hello,
Do you know if there is a demo report that uses the new NP(Codeunit) function?
Thanks,
Elena
5 comments
-
Jet Reports Historic Posts I doubt that there are any demo reports that use NP(Codeunit) because you have to actually have a code unit in Nav that does something interesting and that codeunit has to be published on the Nav 2009 web services tier in order to call it. It would take more than just a report to demo it; it would take a sample code unit that did something interesting as well and that codeunit would have to be added to Nav and published to the web services tier.
Typically the pattern that people use with NP(Codeunit) is that they create a Nav codeunit which calls other Nav codeunits and writes the results of some complex calculations out to a temporary table. Then in the Jet report, you call that function via NP(Codeunit) and then you have other Jet function which access the temporary table and reference the NP(Codeunit) function (this ensures the NP(Codeunit) function will be evaluated first so the data in the temporary table will be populated).
Does this make sense?
Regards,
Hughes -
Jet Reports Historic Posts Hi Hughes,
Thanks for the detailed explanations. I'll give it a try and see what I'll get.
Elena -
Jet Reports Historic Posts I could set-up a test-case, but I was wondering when the NP("Codeunit") gets called. Before running the report, after or depending position in the middle?
-
Jet Reports Historic Posts It gets called while running the report. The order it gets called depends on where it is in the Excel calculation chain. This is why I said in my previous post that typically you make your other Jet functions reference this function, which ensures that it will get called first. So even if you just made the NP(Codeunit) function return * and then you referenced that from a filter in your NL(Rows) function, that would ensure the NP(Codeunit) function got called first because Excel will always evaluate the dependent functions first. Does that make sense?
Regards,
Hughes -
Jet Reports Historic Posts I am trying to use this NP(Codeunit) in a simple example to caclulate the total weight of a sales invoice.
This could be a good example to have available for everyone if I can get it to work.
Each item has been set with the Weight in the Item Unit of Measure table.
I have created a codeunit and function in the codeunit called CalcWeight that takes the parameter of a document no.
within the function I am writing the result to a new table I have created with the document no. and the total weight.
I have published this codeunit as a webservice called Jet_FunctionsCalcWeight(VAR DocNo : Code[10]) : Decimal SalesInvLine.SETRANGE("Document No.",DocNo); SalesInvLine.SETRANGE(Type,SalesInvLine.Type::Item); IF SalesInvLine.FINDFIRST THEN REPEAT IF ItemUOM.GET(SalesInvLine."No.",SalesInvLine."Unit of Measure Code") THEN BEGIN TotalWeight += SalesInvLine.Quantity * ItemUOM.Weight; END; UNTIL SalesInvLine.NEXT = 0; DocWeight.INIT; DocWeight."Document No." := SalesInvLine."Document No."; DocWeight."Total Weight" := TotalWeight; DocWeight.INSERT;
In the jet report I have a row replicator giving out the document no. from Sales Invoice Header. F10 is the cell reference for the document no.
I also then have the jet formula
=NP("Codeunit","Jet_Functions","CalcWeight",$F10)
I then have another jet formula to read the result from the new Document Weight table
=NL("First","Document Weight","Total Weight","Document No.",$F10)
I keep getting weird jet errors - "Attempted to access unloaded AppDomain"
What have I done wrong?