Skip to main content

Notifications

MSDyn365FO: Sending email alert once recurring job finished

Sukrut Parab Profile Picture Sukrut Parab 71,645 Moderator

While using recurring integrations, progress of recurring data jobs or  Data packages jobs can be monitor from System Administration workspace > Data management IT > Recurring data jobs , as shown in below screen

image003.jpg

If you want to send an alert immediately when the message status changes to  any other status  other thans Processed following code  is useful.   You can just do COC on

DMFIntegrationBridge class Import method check for the status of message and send alert . I am doing it for specific processing group instead of doing it for all in the below code.. 

using Microsoft.Dynamics.Platform.Integration;
using Microsoft.Dynamics.Platform.Integration.Azure.Account;
using Microsoft.Dynamics.Platform.Integration.Azure.Blob.Provider;
using Microsoft.Dynamics.Platform.Integration.Connectors.Contracts;
using Microsoft.Dynamics.Platform.Integration.Connectors.Runtime;
using Microsoft.Dynamics.Platform.Integration.Framework.Contracts;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.Dynamics.Platform.Integration.Storage.StorageProvider;
using Microsoft.Dynamics.AX.Framework.Tools.DataManagement.Serialization;
using Microsoft.Dynamics.ApplicationFoundation.DIXF.Instrumentation;
using System.Net;

[ExtensionOf(classStr(DMFIntegrationBridge))]
final class MyDMFIntegrationBridge_extension
{

   

    public IntegrationBridgeResults Import(IntegrationBridgeContract bridgeContract)
    {
               
        Str                                 subject,body;
        InteropPermission                   interopPermission;
        Parameters                          parameters = Parameters::find();
        SysEmailParameters                  parameters = SysEmailParameters::find();
        IntegrationActivityMessageTable     activityMessageTable;

        IntegrationBridgeResults bridgeResult = new IntegrationBridgeResults();
          

        bridgeResult = next Import(bridgeContract);

        if(parameters.ImportDefinitionGroup)
        {
           

            Activity activity = bridgeContract.Activity;
               
       
            ActivityMessageContext activityMessageContext = bridgeContract.ActivityMessageContext;

            activityMessageTable = IntegrationActivityMessageTable::find(str2Guid(activityMessageContext.MessageId));

            subject = "XXXXX integration failure";

            SysSQLSystemInfo   systemInfo =  SysSQLSystemInfo::construct();


            Body = strFmt("Server : %1 , Message id-  %2 is failed for company %3 , Please review and take necessary action." ,systemInfo.getLoginServer(), activityMessageTable.MessageId,activityMessageTable.ContextDataAreaId);

            interopPermission = new InteropPermission(InteropKind::ComInterop);
            interopPermission.assert();

       
            if(bridgeResult.Status == IntegrationBridgeStatus::StagingError || bridgeResult.Status == IntegrationBridgeStatus::TargetError )
            {
                SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();

            messageBuilder.addTo(parms.AdminEmailNotification)
                        .setSubject(Subject)
                        .setBody(Body);
                    
                messageBuilder.setFrom(parameters.SMTPUserName);

                SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());
            
                CodeAccessPermission::revertAssert();
                            }
        }


       

        return bridgeResult;
    }

}

Comments

*This post is locked for comments