Word Automation Problem When Using NAS

seff_yohansonseff_yohanson Member Posts: 23
Hi guys,

I have a problem running word automation tasks in a codeunit using a NAS that I have been trying to figure out for hours.

The original code saved a word file as a PDF. When running the codeunit manually from the object designer it saved a PDF fine, but the same codeunit run by the NAS doesnt do anything and left a copy of WinWord.exe open as a process in the task manager.

I then simplified the code as much as I can so I can try and figure out what is happening but I still have the same issue. My (simplified) code have in a codeunit is as follows:
docPath := 'c:\...\name.doc';

IF ISCLEAR(WrdApp) THEN
   IF NOT CREATE(WrdApp, TRUE) THEN
     ERROR('error! failed to create word app');

WrdApp.Visible := TRUE;
WrdApp.Documents.Open(docpath);

Again when running manually the document opens. When run using a NAS (using the same windows logon) nothing happens, and winword is left running in the background. Im using NAV 5.1 UP2, word 2003 (tried 2010 too!)


Thanks for any help,
Marc

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Does the NAS write any errors to the windows event log?

    You can also try to debug the nas to see where it stops.
  • ppavukppavuk Member Posts: 334
    WrdApp.Visible := TRUE;

    could be an answer. NAS do not support user interaction, and no visible controls can be invoked. But, I also heard somewhere that word automation cannot be run on nas at all, but newer tried.
  • seff_yohansonseff_yohanson Member Posts: 23
    Thanks guys for your help. I have tried the windows logs and nothing :(

    I also tried debugging it before and this works fine! It has previously been running fine under a NAS on windows server 2003 but we are in the progress of moving to a new server (2008 r2 64-bit) hence trying to get it to work

    I may have spotted some the problem - the automation variables have lost their 'subtype' - simply saying "Unknown Automation Server.Application".

    I have now corrected this, however, one variable will not compile! I even created a test table, added the single variable below and get the error below. Help!

    Name DataType Subtype Length
    WrdApp Automation 'Microsoft Word 14.0 Object Library'.Application


    The variable WRDAPP::MAILMERGEDATASOURCEVAL is definaed more than once. An example could be: ;File' exists as both a data typr and a global variable.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Try shorten your variable to just one letter.

    And read the info in this link: http://support.microsoft.com/default.as ... -us;257757
    This tells us:
    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
    So if it works, you are lucky. If it doesn't, you are on your own.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • seff_yohansonseff_yohanson Member Posts: 23
    I did see this, and thought I might have problems. Just wanted to see if anyone had similar issues.

    Odd how the variable below just wont compile, which must be a fairly basic thing?
    WrdApp Automation 'Microsoft Word 14.0 Object Library'.Application
  • ppavukppavuk Member Posts: 334
    had the same problem, when "excel 14 automation" var was defined globally. Works ok if defined locally, and passed to functions as reference.
  • ta5ta5 Member Posts: 1,164
    Hi
    Just my two cents:
    I think this has been discussed in another thread, but if its not possible to declare the automation as a local, you also can export the object as text and delete the whole section with the events and then import it back. Nav COM interface distinguishes on first (or so) characters of functions only, so it happens that some functions appear more than once.

    Regards
    Thomas
  • seff_yohansonseff_yohanson Member Posts: 23
    Thanks guys! :) This helped the object compile. Still no luck running automation using a NAS. Upgraded a test DB to 2009 r2 and the same happens. I am going to try earlier versions of Word to get earlier versions of the automation objects see if I have any more luck.

    If this is not recommended can anyone suggest an alternative? Reading the article again it refers to using "Open XML file" code using .NET - is this the only option? Seems a very complicated implementation.. :-k
  • ta5ta5 Member Posts: 1,164
    Can you try to run the codeunit as the nas user (windows user) and on the same machine where nas runs?
  • seff_yohansonseff_yohanson Member Posts: 23
    Runs fine under the same windows (domain) user that is set up to run the NAS.
  • ta5ta5 Member Posts: 1,164
    Running on the nas machine?
  • seff_yohansonseff_yohanson Member Posts: 23
    Yes - in our test environment the DB, NAS and client are all running from the same machine...and I am logged on as the user running the NAS.
  • seff_yohansonseff_yohanson Member Posts: 23
    In the live environment that we are building there we have now had some success :) by installing word 2003 (which worked straight off) then upgrading to word 2010 (it still worked), which is very bizzare!!!

    So I thought we had found the the solution. But tried doing exactly the same on another identical live server (and our test server) and no automation using even using word 2003!
  • ta5ta5 Member Posts: 1,164
    In the live environment that we are building there we have now had some success :) by installing word 2003 (which worked straight off) then upgrading to word 2010 (it still worked), which is very bizzare!!!

    So I thought we had found the the solution. But tried doing exactly the same on another identical live server (and our test server) and no automation using even using word 2003!

    And still manually ok, but not with nas, isn't it?
  • seff_yohansonseff_yohanson Member Posts: 23
    Yes, manually running the codeunit = fine, NAS running = winword.exe left open in the task manager for every time the NAS runs the codeunit. Eventually it woud run out of memory with multiple winwords open. we have just found the same happens for excel.
  • ppavukppavuk Member Posts: 334
    As i understand functionality itself works, but winword process left alive at end of your code execution? If so - you can just kill process using Taskkill /IM winword.exe /F at end of your code.
  • seff_yohansonseff_yohanson Member Posts: 23
    Hi, just wanted to say thanks to everyone for their help. I found the solution in another article on Mibuso (wish I had found this a couple of weeks ago :roll:

    viewtopic.php?t=51723

    To simply and confirm the simplified situtation in case any one else has this isssue - I had a Codeunit with one function to open a word document from a fixed location and save as a PDF. When :
    * Run from object designer it saved the file succesfully
    * When using command prompt to start the NAS in degbug mode it worked
    * When run by the NAS (function call in codeunit 1) it failed, with no error messages (including event log) to help debug. Windowrd.exe was left running in the task manager

    As soon as the folders below were created it worked fine!!! :D

    C:\Windows\SysWOW64\config\systemprofile\Desktop
    C:\Windows\System32\config\systemprofile\Desktop

    Thanks again
  • ppavukppavuk Member Posts: 334
    Are you running NAS under domain user or under "network service" user?
  • seff_yohansonseff_yohanson Member Posts: 23
    Under a domain user, with full administrator permissions
Sign In or Register to comment.