Hi experts,
I'm trying to use the DotNet variables in NAV2009R2, the Microsoft.Office.Interop.Word assembly to create some automated document creation. Looks like it works in the beginning but I have a little problem. Almost all of the methods require parameters as "ref" - wordApp.Documents.Add(ref object Template, ref object NewTemplate, ref object DocumentType, ref object Visible). Everything works fine if I pass the parameters in variables. The problem is that these parameters are optional. In C# I can just simply define missingObj as System.Reflection.Missing.Value, but I don't find any equivalent in C/AL. If I define some dummy variable and pass it, I get TypeMismatch exception. If I pass correct parameters (Text,Boolean,Integer,Boolean) it works fine.
So the question is: Is there any way to pass "Missing" parameters. I've tried already to define Missing in C/AL as System.Reflection.Missing (mscorlib.dll), also tried to pass Variant data type... no luck
Answers
To make it short, you'll need to pass actual variables.
Alternatively - but I haven't tried that! - you may want to create a .NET class with a function which returns object, like this:
Then call that class, and assign a value to a Variant variable in C/AL:
Then pass this MyCALVariant wherever Missing is needed.
As I said - I can't guarantee this will work, as I am only theorizing here, don't have time at the moment to test this concept. Please do let me know if it works, or fails. I'd like to know.
http://vjeko.com/
EDIT: btw, I attended at your presentation, it was one of the best for me on NAVTechDays
Thanks, Mihail! :thumbsup:
http://vjeko.com/
anyway the most interesting lines from the eventvwr:
Could you share your .NET code as well as your NAV code where you are calling this?
http://vjeko.com/
I already unregistered the assembly but the NAV code looked like this:
as Automation variable:
as DotNet variable:
EDIT: and one offtopic: I'm already cool with the fact I can't pass "Missing", but I got another problem with the Microsoft.Office.Interop.Word assembly. In the Document element we got property Tables, and Tables have property Item(int index) which return a table element. Looks fine but when I try to call the Tables.Item(1) navision says
do you have any suggestion why this is happening?
http://vjeko.com/
Just a note - I left the DotNet variable and instead I took the Automation equivalent - 'Microsoft Word 14.0 Object Library'. When using the automations you can pass or not pass the optional parameters, the rest of the code is the same, you should just CREATE the automation and CLEAR it at the end (and I don't need to register any custom components on client machines ).
C/AL:
C#:
Both of the above approaches work (returning object and Missing). C/AL simply does what it's intended to do, no crashes.
What I can only assume is what IsakssonMi says - if you are trying to wrap that into COM, it will fail due to the limitations of COM, not .NET (or DotNet). That may explain the indexer failure, as well.
http://vjeko.com/
Niels-Henrik Sejthen
Senior Software Developer
Microsoft Dynamics NAV
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
In your CAL Example; What Type ar the Variables: Missing, Optional?
Forgot the question!!!!
First time I think the CAL-Code is Stamd alone!
1. Geting to the Type.Missing value by yourself: 2. Use library provided by Microsoft with latest NAV Versions:
P.S.: Don't forget to check variables parameter RunOnClient.
I'm getting a similar issue (need to populate a missing value) and trying to resolve it using 2mas' solutions, avoiding DLLs. But I'm not being able to use the GetMissingValue() function from the integration helper library as suggested by 2Mas (suggestion number #2).
If I do it I get "The parameter is incorrect". I wonder if I'm not using it correctly? If anybody could share an example it would be great.
If I look to his suggestion #1, I don't find the libraries mentioned (System.Reflection.FieldInfo or System. Type, nor System.Object). What am I doing wrong? Am I missing some component that I need to install on the server?
Thanks!
Tomas