Friday, July 30, 2010

Making Modifications to Report Libraries in AX and Re-Deploying the Latest Versions to SSRS

   
Creating and initially deploying a Report Library into SSRS is quite easy. However when it came time to make a modification to that Report Library, I quickly found out that my latest version was not actually deploying, because changes were not actually being made to my Report Library in the AOD, despite the fact that Visual Studio was reporting success with a message such as: “Saving project [Project Name] and all its items to AOD succeeded”. The problem appears to be that when clicking “Save to AOD” in Visual Studio, for a project that already exists in AX, the project isn’t actually overwritten. To resolve this, follow these simple steps when making a mod to a Report Library.

1. Right-Click the Report Library that you want to edit, and select “Edit in Visual Studio”
2. If you are prompted with an overwrite prompt, click “Yes to All”
3. Make your modifications
4. When ready to save back to AX, select: File > Save All
5. Go back into AX and Delete the Report Library that you are editing
6. Go back into Visual Studio, right-click the Project, and select “Save to AOD”
7. Go back into AX, right-click the Report Libraries node in the AOT, and select “Refresh” and you will see your Report has returned, now being your most recent version.

Other things to keep in mind

If your Report Library is the defined Object of a Menu Item, and there is a chance that you may have modified the Name of the Report while editing it, make sure that you check the Object value of the Menu Item to verify that it is valid (otherwise, the Menu Item will point to the previous version of the report in SSRS).

If you Import the edited Report Library into another environment, make sure that you Delete the existing Report Library first. I have found that the Import does not always overwrite the existing Report Library, even during an import.
   

Thursday, July 29, 2010

Sending Emails From Dynamics AX without Outlook

  
Recently we had a need to have Dynamics AX send emails without the use of Outlook. I was presented with the following blog by Mohammed Rasheed titled Sending Emails From Dynamics AX without Outlook, which proved to be extremely useful. There was however an issue with the code (perhaps simply related to our environment) which was puzzling. The problem was that the email would send successfully, but afterward, an error was thrown stating:

ClrObject static method invocation error

The line of code that appeared to be the culprit was basically the last line in the function:

CodeAccessPermission::revertAssert();

However, after analyzing things more closely the problematic line was actually the line just above:

winApi::deleteFile(fileNameforEmail); // delete temp file

As it turns out, the deleteFile() function was failing because the file had not been released by a previous process. Though it was a bit painful to figure out what was going on, the solution itself was rather simple.

Immediately after sending the email, I modified the code to dispose the objects that may have been clinging to the file

mymail.Send(mailmessage);


mailmessage.Dispose();
attachment.Dispose();

After this, the file was released, and was able to be deleted, and the error went away!