Wednesday 6 October 2021

Send a sales order as PDF attachment in Microsoft Dynamics NAV 2017

 Hello reader here is the code snippet to achieve the above


//Check the sender's email

IF UserSetup.GET(USERID) THEN

  EmailID := UserSetup."E-Mail"//Get the sender's email adress from Approval user setup table

ELSE

  ERROR(MSL0001,USERID);//Display error is the address above is not found

SMTPMailSetup.GET;// table 409

SaleTable.RESET;// Sales header table 36

SaleTable.SETRANGE("Document Type",SaleTable."Document Type"::Order);

SaleTable.SETRANGE("No.",SalesOrder."No.");


IF UserSetup.GET(USERID) THEN

  EmailID := UserSetup."E-Mail"

ELSE

  ERROR(MSL0001,USERID);


IF SaleTable.FINDFIRST THEN BEGIN

  SalesOrderDoc.SETTABLEVIEW(SaleTable);

  FileName := FileMgt.ServerTempFileName('pdf');//Defining the report attachment type [FileName is Text variable]

  REPORT.SAVEASPDF(50071,FileName,SaleTable);// 50071 is the report ID for the sales order confirmation report

  CLEAR(SMTPMail);// Code Unit 400

  SMTPMail.CreateMessage(USERID,SMTPMailSetup."User ID",EmailID,'Booked Sales Order','Please find order confirmation '+SalesOrder."No.",TRUE);

  SMTPMail.AddAttachment(FileName,'Sales Order '+SalesOrder."No."+'.pdf');// Adds the report as attachment


  SMTPMail.AppendBody('<br>');

  SMTPMail.AppendBody('Kindly find the attachment ');

  SMTPMail.AppendBody('<HR>');

  SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this mail!');

  SMTPMail.Send;

  MESSAGE('Mail Sent');

END;



Thats it. Good luck

Credit CloudFonts

Tuesday 5 October 2021

Error 'The value 01/07/21 cant be evaluated into type date'




 I happened to encounter the above error. The rest of the users can run the same report without any issue. The problem is isolated to just this single user.

First i noticed the date format on the users PC is set to dd/mm/yy.

  • To resolve the issue, change the date format to mm/dd/yy on the user's PC
  •  Run the report, clear any date filters that are set on the report request page
  • close the report
  • Change the date format settings back to dd/mm/yy on the PC
  • Close NAV and restart NAV
  • The issue should be resolved


Sunday 31 January 2021

Uploading Development License to Business Central V17 on premise

 Hello reader. I would like to share something that took me some minutes to learn.Obviously if you are new to BC moving from older versions of NAV. You are used to importing the development license via development environment. In Business Central V17, things changed a bit, now uploading the license is done via Administration Shell using a few commands.

To make things easy, first move your development license to C:\ directory.

Run Business Central Administration Shell as administrator

Check the existing license information by executing command Export- NavServerLicenseInformation

The system will prompt you for the serverInstance  e.g BC170

Executing the command will display the license information.



Upload the new development license

With you Administration shell open.

  • Run Import-NAVServerLicense command
  • Provide licenseFile path in my case its in C: & the BC17.flf is the file name
  • Provide ServerInstance in my case BC170
  • Restart-NavServerInstance as in preceeding screen shot


You may check whether the new license is uploaded by running the command as in screen below



Good luck!!!

Credit  GoDigit