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