Email notification for approval request n Dynamics NAV 2017

Hi team,

I am working on Leave application for HR, I created a page called Leave application (Status::Open) which contains page actions: Send approval request which i added the code below:

Global Variable:

EmployeeLeave Record Employee Leave Application

EmployeeLeave.RESET;
EmployeeLeave.SETRANGE("Application No","Application No");
IF EmployeeLeave.FIND('-') THEN BEGIN
  EmployeeLeave.Status := EmployeeLeave.Status::"Pending Approval";
  EmployeeLeave."Approval Date" := TODAY;
  EmployeeLeave."Approved Start Date" := TODAY;
  EmployeeLeave.MODIFY;
  MESSAGE(Text001,"Application No");
END;

I also have another page called Leave application - Pending (Status::Pending Approval) which contains page actions: Approve and Reject. They also have there varies code and link to another pages.

I have setup the followings:

1.) SMTP Mail Setup,

2.) Approval User Setup (Approval User Setup Testing, Notification Setup).

The code above is working fine but it’s not send to the email of the employee in charge.

My question is that I want the approval request to be send to the emails of my employees.

Thanks.

Aeehhhmm, There’s no Email-sending code there, so it’s quite hard to tell you why it’s not working…

Yes, there is no email- sending code.

And I need the email-sending code.

Thanks

And what do you mean by approval user setup? Is this something you want to manage via the standard approval workflows?

aehhmm what have you tried? Do you expect us to give you the code for sending emails? Have you looked at how standard-functionality works.

I mean - if you cannot yourself figure out how it is done in standard NAV… then you should NOT do NAV development at all…

(Sorry if you find it rude - but this is REALLY basic stuff)

Smiling. But the method am using is not standard approach. And there is a big different from the standard. When it comes to you guide. Thanks

In approval user setup, I have the User ID, Approval ID and E mail.

No, I think there should be a way of solving it through this method. If not you can guide me with the standard approval workflow. But the leave application (Status: Open) and Leave application - Pending (Status: Pending Approval) are in different Role Center

Declare Mail varaible codeunit SMTP mail

IF user id <> ‘’ THEN BEGIN
IF UserSetup.GET(user id) THEN BEGIN
SubjectText := ‘Your notification subject’
BodyText := ‘your body text’;
Mail.CreateMessage(‘EMPLOYEE’,‘From Email’,usersetup.email,
SubjectText,BodyText,TRUE);
Mail.AppendBody(’

’);
Mail.AppendBody(‘User id :’+’ ‘+FORMAT(USERID));
Mail.AppendBody(’
’);
Mail.AppendBody(‘Date :’+’ ‘+FORMAT(TODAY));
Mail.AppendBody(’
’);
Mail.AppendBody(‘Time :’+’ ‘+FORMAT(TIME));
Mail.AppendBody(’
’);
Mail.AppendBody(’

’);
Mail.Send;
end

end;

More power to your elbow.

Am grateful, Thank you very much.

I did as you said, when i click the send request approval buttom. I received error message: The email address “From Email” is not valid but the email address is valid.

Thanks

This is exactly why i said that before anyone simply request some lines of code - one simply has to try to find out how it works first - and then find the code that exists in the system.

the ‘FROM EMAIL’ is not a valid email-address :wink: - You have to read and understand the code above - its not valid code - but an example

Okay.

Thanks

Oh Boy… I just gave you a example, you have to substitute appropriate values into these fields. I don’t know what is your field name and table structure.

IF "User ID" <> '' THEN BEGIN
IF UserSetup.GET("User ID") THEN BEGIN
SubjectText := 'Microsoft Dynamics NAV Notification'; 
BodyText := 'Microsoft Dynamics NAV Approval System';
SMTPMail.CreateMessage("Employee Name",UserSetup."E-Mail",'Ishaka.Harisu@npf.com',SubjectText,BodyText,TRUE);
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('Leave Application'+' '+'<br>Application No:<br>'+' '+FORMAT("Application No")+' '+'has sent for an approval request.'); 
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('<b>User ID:</b>'+ ''+FORMAT(USERID));
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('<b>Date:</b>'+ ''+FORMAT(TODAY));
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('<b>Time:</b>'+ ''+FORMAT(TIME));
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('<br>');
SMTPMail.Send;
MESSAGE('Mail send');
END;
END;

Its working now, In case I have more than one email address to send to. How should I do it.

Thanks

If the recipients are all listed in your usersetup table you can put your code above in a Repeat… Until Loop like this:

UserSetup.RESET;

UserSetup.SETRANGE(somefilter);

if UserSetup.FINDSET THEN BEGIN

REPEAT

… your code

UNTIL UserSetup.Next = 0;

Mail.Addcc(EmailID) ; //EmailID is an example, you have to use actual email id.

Thanks.

Thanks.