E-Mailing PDF Report with Job Queue

One of my clients asked for a automated report delivery every morning.  Since Job Queue was already running I decided to create a way to have Job Queue print the report to PDF and email it as an attachment.

This example uses the E-Mailer Report no. 50003 to send Report No. 6 to my email address.

First I had to make some changes to codeunit 449, Job Queue Start Codeunit, the OnRun trigger.  I created a local variable with the name JobQueueEntry as a Record 472 and then added to the code.
[code htmlscript=”false”]CASE "Object Type to Run" OF
"Object Type to Run"::Codeunit:
CODEUNIT.RUN("Object ID to Run",Rec);
"Object Type to Run"::Report:
//#01
IF "Parameter String" <> ” THEN BEGIN
JobQueueEntry := Rec;
JobQueueEntry.SETRECFILTER;
REPORT.RUN("Object ID to Run",FALSE,FALSE,JobQueueEntry);
END ELSE
//#01
REPORT.RUN("Object ID to Run",FALSE);
END;[/code]
Attached is report 50003 that does the job.

Any Report E-Mailer

Employee Attendance via Web Services

In my older version of Time Registration for Dynamics NAV I had ASP web site working on Microsoft SQL server that is used as an attendance list for an office.  On the web site by clicking on the employee name a page with punch in or punch out appears.  From the older system the user had to manually synchronize the external SQL database.

On the new version of Time Registration for Dynamics NAV I am using the new web service support of NAV 2009.  The task was to change the ASP web site and remove the SQL server connection on the web site.  The result is a success, the web site is available here.  The data is directly from Dynamics NAV and all updates are directly inserted into Dynamics NAV.

URL Encoding

I was reading Freddys Blog and found a function to encode URI Component.  I tested the function but found that I needed to change the function to correctly encode my URL.

In Iceland the Company Names in many cases include characters in the range from 128 to 255.  This new function can handle this upper range correctly.

URIEncoder

NAV Web Service and PHP

I wanted to replace MySQL with NAV Web Service as a data source for my PHP web site.  I started to look around and found all I needed in Freddys Blog.  First post is about changes in authentication method of the web service, the later post displays the code needed to connect to the web service with php.

I have an php web on my Windows Home Server and needed to activate two more extensions to get things working.

Here are the php files that I used – PHP consume NAV Web Service

Example on using NAV Web Service in NAV C/Side

Some of our clients are using LS Retail.That solution supports stand-alone POS terminals that are running Microsoft Dynamics NAV.  It is therefore easy to allow these terminals to be used also as a punch clock.

This punch clock starts up a background process to handle synchronization via web services.  Attached is a demo c/side code on how the web services are consumed.

SyncEmployees

Example on using NAV Web Service in Visual Studio vb.net

This is using the web service in my previous post.  In Visual Studio I start by adding the web reference.  Select Project -> Add Service Reference

Then select Advanced…

Then Add Web Reference…

Where I insert URL encoded string for the published codeunit including the company name.

I created a form with a listbox object and a button.  I used this code to insert all employee no’s into the listbox.
[code htmlscript=”false” lang=”vb”]Public Class Form1
Dim ClockID As String
Dim Success As Boolean
Dim DefCred As Boolean
Dim ResponseMessage As String
‘The Web Service
Dim NAVPunch1 As New WebService.NAVPunch
‘New set of credentials
Dim User As New System.Net.NetworkCredential

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If DefCred Then
NAVPunch1.UseDefaultCredentials = True
NAVPunch1.Url = ""
Else
User.Domain = ""
User.UserName = ""
User.Password = ""
NAVPunch1.Credentials = User
NAVPunch1.Url = ""
End If
ClockID = "{4A212826-CAF3-4E3C-9D97-6923A692A209}"

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
‘ Get Employee List
ResponseMessage = ""
ListBox1.Items.Clear()
Dim EmployeeList As New WebService.EmployeeList
Try
Success = NAVPunch1.GetClockEmployees(ClockID, _
EmployeeList, _
ResponseMessage)
CheckBox1.Checked = Success
TextBox1.Text = ResponseMessage
If Success Then
For Each Employee In EmployeeList.Employee
ListBox1.Items.Add(Employee.No)
Next
End If
Finally
End Try
End Sub
End Class[/code]

Creating Web Services in NAV 2009

I have been working on NAV Time Registration and the solution is almost ready.  The last step was to create a web service that supports stand-alone punching clocks, both in .net c# and also as a NAV client.

The web service is a standard codeunit with functions.  I make sure the functions that are not to be published have the Local property set to Yes.

Using XMLport in web services requires a few parameter changes.  First I include them in the function parameters.  I use a boolean parameter in Return Value as a success flag.

Then in XMLport properties I change direction to export, change format to XML and select to use default namespace.

The C/Side code to answer this web service is.
[code htmlscript=”false”]IF NOT ValidateClockID(ClockID,ResponseMessage) THEN BEGIN
InsertLog(ClockID,Log.GetEmployeeList,FALSE,ResponseMessage,”);
EXIT(FALSE);
END;

IF NOT CreateEmployeeBuffer(EmployeeBuffer,ResponseMessage) THEN BEGIN
InsertLog(ClockID,Log.GetEmployeeList,FALSE,ResponseMessage,”);
EXIT(FALSE);
END;

EmployeeList.SetEmployeeList(PunchClock.Code,EmployeeBuffer);
ResponseMessage := Text033;
InsertLog(ClockID,Log.GetEmployeeList,TRUE,”,”);
EXIT(TRUE);[/code]
Then finally I run form 860, Web Services and add a line for this web service to be published.

Next post is a demonstration on how to use this web service.  I used Freddys multiple service tier post in my developement enviroment to setup NAV services.

 

Scanning in Remote Desktop

When running Dynamics NAV as a Remote Application or in Remote Desktop you are missing connection to your locally connected scanner.  I have created a solution that uses a standalone application running on the client computer.  That application uses the TwainControlX from Ciansoft and connects to a Microsoft SQL database.  The database needs to be on a computer that both the client computer and the remote desktop computer have access to.

On that database server a database is created with only one table.  That table can be truncated every night in a maintenance job.  This is the table creation script.

The program on the client then connects to the database and to the scanner.

A code in Dynamics NAV creates the request for a scan by inserting a entry into the ScanRequest table and the application on the client computer automatically scans the images and updates that scan request entry.  The updated entry then containes the image file that is imported into Dynamics NAV or attached as a link.

The following ZIP files are encrypted.  View the Product page for more information.

Twain Scanner (ISL)
NAV Myndlestur (TwainOCX) Source Code (ISL)