Friday, April 19, 2024

SSMS query in VS

How to run SSMS query in Visual Studio for Dynamics 365 FO

1. Open Visual Studio on your dev server

Visual studio

2. click on view then select SQL server object explorer as shown below

Visual studio home

3. SQL server object explorer will be shown on the left side in Visual Studio as shown below, click on add SQL server

SQL server object explorer

4. A new window will open as shown below

Connect visual studio

5. Fill in the server name as shown below and click connect

Visual studio ssms

6. Now you will see your DB in Visual Studio, expand your AxDB as shown in the below picture, then right-click on DB and click on new query

Visual studio

7. A new query window will open

Visual studio SQL query editor

8. write your query and click on run

SSMS query editor

In this way we can connect our DB in Visual studio instead of SSMS


Tuesday, April 16, 2024

User Conditional Access

Block access by location with Microsoft Entra Conditional Access

Conditional access policy azure

Below are the key points for implementing location-based access controls using Microsoft Entra Conditional Access:

1. Purpose: Enhancing security by restricting access based on user location to prevent unauthorized access.

2. Mechanism: Utilizing Conditional Access policies that analyze signals from the user, their device, and their location to make automated decisions on access.

3. Application: This affects Dynamics 365 applications where access is denied if a user logs in from a blocked location.

4. Subscription Requirement: Available for users with Microsoft Entra ID P1 or P3 subscriptions.

5. Setup Requirements: Requires a federated Microsoft Entra ID tenant.

6. Policy Enforcement: Access restrictions are enforced during user authentication but allow access until session timeout, even if the user leaves the designated location.

7. Configuration Steps:
   - Create named locations. Define location
   - Establish Conditional Access policies. Create conditional access policy
   - Select relevant Microsoft applications under Cloud apps or actions for the policies.

8. License Requirement: Conditional Access settings are accessible with a Microsoft Entra ID Premium license.

Microsoft Reference:

Monday, April 8, 2024

Send Email

How to send email via X++ code D365 FO DynamicsCommunity101

How to send email via X++ code D365 FO

1. First step on How to send email via x++ code D365 FO, we will create a class and a static method in it as shown below

/// <summary>
/// Send mails
/// </summary>
class LSSendingMail
    /// <summary>
    /// Send EMail
    /// </summary>
    /// <param name = "_toEmailid">_toEmailid</param>
    /// <param name = "_template">_template</param>
    /// <param name = "_placeHolderMap">_placeHolderMap</param>
    public static void sendMail(LSEmailAddress _toEmailid, SysEmailSystemId _template , Map _placeHolderMap)
        SysOutgoingEmailTable   outGoingEmailTable;
        SysEmailSystemTable SysEmailSystemTable = SysEmailSystemTable::find(_template);
        SysEmailMessageSystemTable SysEmailMessageSystemTable = SysEmailMessageSystemTable::find(_template,#language);

        str messageBody = SysEmailMessageSystemTable.Mail;
        str subject = SysEmailMessageSystemTable.Subject;
        messageBody = SysEmailMessage::stringExpand(messageBody, _placeholderMap);
        subject     = SysEmailMessage::stringExpand(subject, _placeholderMap);
        outgoingEmailTable.EmailItemId                  = EventInbox::nextEventId();
        outgoingEmailTable.TemplateId                   = _template;
        outgoingEmailTable.Sender                       = SysEmailSystemTable.SenderAddr;
        outgoingEmailTable.SenderName                   = SysEmailSystemTable.SenderName;
        outgoingEmailTable.Recipient                    = _toemailid;
        outgoingEmailTable.Subject                      = subject;
        outgoingEmailTable.Message                      = messageBody;
        outgoingEmailTable.Priority                     = SysEmailSystemTable.Priority;
        outgoingEmailTable.WithRetries                  = true;
        outgoingEmailTable.RetryNum                     = 0;
        outgoingEmailTable.UserId                       = curuserid();
        outgoingEmailTable.Status                       = SysEmailStatus::Unsent;
        outgoingEmailTable.LatestStatusChangeDateTime   = DateTimeUtil::getSystemDateTime();


    /// <summary>
    /// Send email attachment
    /// </summary>
    /// <param name = "_toEmailid">_toEmailid</param>
    /// <param name = "_template">_template</param>
    /// <param name = "_placeHolderMap">_placeHolderMap</param>
    /// <param name = "docuRef">docuRef</param>
    /// <param name = "_fileType">_fileType</param>
    /// <returns>boolean</returns>
    public static boolean sendMailwithAttachment(LSEmailAddress _toEmailid, SysEmailSystemId _template , Map _placeHolderMap,DocuRef docuRef, Str _fileType = 'application/pdf')
        boolean messageSent;
        Map sysMailers = SysMailerFactory::getMailers();
        SysEmailSystemTable SysEmailSystemTable = SysEmailSystemTable::find(_template);
        SysEmailMessageSystemTable SysEmailMessageSystemTable = SysEmailMessageSystemTable::find(_template,SysEmailSystemTable.DefaultLanguage);

        str messageBody = SysEmailMessageSystemTable.Mail;
        str subject     = SysEmailMessageSystemTable.Subject;

        var messageBuilder = new SysMailerMessageBuilder();

        messageBuilder.setSubject(SysEmailMessage::stringExpand(subject, _placeholderMap));
        messageBuilder.setBody(SysEmailMessage::stringExpand(messageBody, _placeholderMap));

        //var message = messageBuilder.getMessage();

        messageBuilder.addAttachment(DocumentManagement ::getAttachmentStream(docuRef),docuRef.Name + '.pdf',_fileType);
        SysIMailer mailer;
        mailer = sysMailers.lookup(#SMTP);

        SysIMailerNonInteractive nonInteractiveMailer = mailer;
        messageSent = nonInteractiveMailer.sendNonInteractive(messageBuilder.getMessage());

        return messageSent;


2. Now to show you the example of how to send email via x++ code D365 FO, we will create a runnable class

internal final class TestAY
    /// <summary>
    /// Class entry point. The system will call this method when a designated menu 
    /// is selected when execution starts and this class is set as the startup class.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)

        Map placeHolderMap = new Map(Types::String, Types::String);
        placeHolderMap.insert(#User, "Atul");
        LSSendingMail::sendMail('', 'Safety Cal', placeHolderMap);

3. Now for 3rd step on How to send email via X++ code D365 FO, for the above code to run you need to set up an email template named "Safety Cal"

1. Go to System email templates 

Path system email template

2. You will see a form like below

email template form

3. Now click on new and create a new template as shown below

New system email template

4. I am filling as below

Filled system email template

5. Once created click on the email message as shown below

Email message button in system email template

6. once you click, you will see a new form like below

Final uploaded email template

7. Here we need to upload the HTML format of our email, I have already attached mine

My HTML sample below

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Safety Calendar Reminder</title>
    <p>Dear %user%,</p>
    <p>A gentle reminder to promptly complete your Safety Calendar entries, due by the end of this week. Your timely contribution is vital for our collective safety and compliance.</p>
    <p>For assistance or queries, please contact us.</p>
    <p>Best regards,</p>
    <p>Microsoft Dynamics 365</p>

4. Now for the last step on How to send email via X++ code D365 FO, you need to run an Email distributor batch, the path shown below

Email distributor batch

Now just run the runnable class that we created in Step 2

Above is the code on How to send email via X++ code D365 FO by DynamicsCommunity101

Year End Close Procedure

D365 Finance and Operations - Year End Close Procedure on DynamicsCommunity101

Wednesday, April 3, 2024

Power Platform to assign licenses

Assign Licenses with Intelligent Recommendations in Power Platform - Public Preview | DynamicsCommunity101

Power platform admin homepage
Click on the picture for the full blog