How do I save the return value that the CMD should deliver in NAV?

Hello everybody,

I have the following problem:
I want to use the CMD from NAV to execute the SET HOMDRIVE function. The return value, i.e. the path, should be stored as a variable in NAV.

This is the code:
HomeDriveL := WshShell.Run('SET HOMEDRIVE');

HomeDriveL is a local variable and is from DataType a Text.

But when executing in NAV I get this error:
Error when calling System.__ComObject.Run with the following message: The system cannot find the specified file. (Exception of HRESULT: 0x80070002)

Can someone help me with that?
Many thanks in advance!

Answers

  • ftorneroftornero Member Posts: 522
    Hello @MaximilianN,

    How you are using an Automation variable i gess that you have a 2009R2 NAV version or even lower, so you can try this:
    HomeDriveL := ENVIRON('HOMEDRIVE');
    

    Regards
  • MaximilianNMaximilianN Member Posts: 4
    Hey @ftornero,

    thanks for your answer. When I use this function, there comes an error message, that this function is an outdated method.

    Do you know whether there is a new one?

    Thank you in advance,
    Maxi
  • ftorneroftornero Member Posts: 522
    Hello @MaximilianN,

    What NAV version do you have ?

    Regards.
  • MaximilianNMaximilianN Member Posts: 4
    @ftornero

    I have NAV 2013R2.
    My problem is that I'm new to C/AL programming.

    Thanks for your help.

  • ftorneroftornero Member Posts: 522
    Hello @MaximilianN,

    You can use a DotNet variable to do that
    Var	Name	DataType	Subtype	Length
    No	EnvVar	Text		
    
  • ftorneroftornero Member Posts: 522
    Hello @MaximilianN,

    Sorry this one
    Name	DataType	Subtype	Length
    GetEnv	DotNet	System.Environment.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    

    And use like this:
    HomeDriveL := GetEnv.GetEnvironmentVariable('HOMEDRIVE');
    
  • ftorneroftornero Member Posts: 522
    Hello @MaximilianN,

    Another thing is that the DotNet variable must be run on client, otherwise it get you the environment var in the server,

    So in the variable properties you must change the value like in the image:

    tjl2q76v00jj.png

    Regards
  • MaximilianNMaximilianN Member Posts: 4
    @ftornero
    Thank you for your help.
    Now it works.
    Ive made it with the DotNet variable and the property RunOnClient.

Sign In or Register to comment.