Create a Word document by using the Com interface and sending it on email.

Hi,

I’m having an issue where a method fully works as intended when called from a Job in ax, but as soon as the same method is called thru a Web service and business connector I’m getting this error:

"COM object of class ‘Word.Application’ could not be created. Ensure that the object has been properly registered on computer ‘AX5SPTEST’. Object ‘COM’ could not be created Microsoft word is not installed"

I’m calling this thru a web serivice hosted on “AX5SPTEST” which have Office 2010 installed, The connection between the IIS box and AOS is done using the standard Business connector. Office 2010 is installed on the AOS, IIS and terminal server.

Calling the same class and methods from a job within ax (both on terminalserver and the AOS) works perfectly.

In short I’m trying to acheive this: From a webservice: calling a method in Ax which creates a word document based on a template and inserting information into the bookmarks, saving the document and creating an email, attaching the document and sending it using the SysEmailTable::sendMail method.

But whenever I try to achieve the same using the web server i get the error above.

am I trying to achieve the impossible here? would rewriting my code to force execution on server be the way to go? What issues would that then give me?

Any insights is greatly appreciated as I’m basicallly completely stuck as to how to solve my issue.

I solved the issue by running the web service impersonated, however I’m running into a different error now;

“Exception (0x800a141f): Word was unable to read this document. It may be corrupt. Try one or more of the following: * Open and Repair the file. * Open the file with the Text Recovery converter”

My code throws this error on the last line in this segment of my code:

Try

{

word = new com(#word);
}
Catch(exception::Internal)
{
if (word == null)
{
throw error (“Microsoft word is not installed.”);
}
}

template = “C:\TEMP\test.dotx”;
EmailTemplate = “TEST”;
languageid = “en-us”;
email = sysuserinfo::find(sysCompanyUserinfo::emplId2UserId(_smaServiceOrderTable.Responsible)).Email;

filename = "\\fileserver.domain.com\Temp\_smaServiceOrderTable.extid + “.docx”;
Userid = sysCompanyUserinfo::emplId2UserId(_smaServiceOrderTable.Responsible);
documents = word.documents();
document = Documents.add(template); //<-------------------------------------------------

The template has been checked and recreated, full permissions given to everyone on the specific file, but to no avail.

I’m quickly going crazy here, any suggestions will be well received!

Hey Franck,

If I’m not mistaking you can’t run the COM Work object on server side. And web services do that.

The COM object uses a UI to do all his executions (UI itself is ‘Hidden’ by default … can be shown to).

Kr,

Dave