Showing posts with label Email. Show all posts
Showing posts with label Email. Show all posts

How to get Vendors or Customer Contact Information Primary & None Primary




 How to get Vendors or Customer  Contact Information Primary & None Primary



Via below code you can get the Vendor/Customer complete contact information (Primary & None Primary).

  LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyLocation        dirLocation;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("S00038").Party);
     
        while select  logisticsElectronicAddress
        join dirLocation  where dirLocation.Location==logisticsElectronicAddress.Location
            && dirLocation.Party==dirPartyTable.RecId
        {
            info(strFmt("%1",logisticsElectronicAddress.Locator));
        }

Support Faryal's Cusine


How to get Vendors or Customer Primary Contact Information




How to get Vendors or Customer Primary Contact Information

Via below code you can get the Vendor/Customer complete contact information.

Important 
In AX 2012 PrimaryContactLinkedInPrimaryContactFacebook fields are not available.

class SLD_DemoInstance
{
   
    public static void main(Args _args)
    {

        LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("K-DR-000001").Party);
     
        while select  logisticsElectronicAddress where (logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactEmail ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactPhone || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFacebook ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFax || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactLinkedIn)

        {
            info(strFmt("%1",logisticsElectronicAddress.Description));
        }
    }


}




Support Faryal's Cusine


Email In CC and BCC D365FO


Email In CC and BCC D365FO


As we all know the feature to send the email in CC and BCC is not yet available on UI, But the sysMailer class has the option to achieve the objective.

Here is the sample code:

class SLD_DemoInstance
{



    public void main(Args _args)
    {
      

        SysMailerMessageBuilder builder = new SysMailerMessageBuilder()
    .setFrom("shaikhsohailhussain@gmail.com")
    .addTo("to@example.com")
    .addCc("cc@example.com")
    .addBcc("bcc@example.com")
    .setSubject("Test")
    .setBody("Test email");
   
        SysMailerFactory::sendNonInteractive(builder.getMessage());

    }

}

Support Faryal's Cusine


Email SSRS Report As Attachment D365FO


SSRS Report Email Attachment Dynamics 365FO



In one of my projects, We have a requirement to send the SSRS report as an attachment to an Email.

As everyone knows that this task is too simple in AX 2012, Where we save the file in client or server file systems and then send it as an Email attachment.

But the things are a bit more complicated when it comes to D365 in the cloud. You are no longer able to save the file locally as storage.

Following is the code to convert the SSRS report in Binaries 




public class ConvertReportPDF
{

    public static void main(Args _args)
    {
       
  
        Filename                        fileName = "P000173_AbcTest.pdf";
        SrsReportRunController    controller = new SrsReportRunController();
        SLD_TaxProfileContract   contract = new SLD_TaxProfileContract();
        SRSPrintDestinationSettings     settings;
        Array                           arrayFiles;
        System.Byte[]                   reportBytes = new System.Byte[0]();
        SRSProxy                        srsProxy;
        SRSReportRunService             srsReportRunService = new SrsReportRunService();
        Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]  parameterValueArray;
        Map reportParametersMap;
        SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
        ;

  
        contract.parmAccountNum('K-VDR-000001');
        contract.parmAccountType(SLD_AccountType::Vendor);
        // Provide details to controller and add contract
        controller.parmArgs(_args);
        controller.parmReportName(ssrsReportStr(SLD_TaxProfile, Report));
        controller.parmShowDialog(false);
        controller.parmLoadFromSysLastValue(false);
        controller.parmReportContract().parmRdpContract(contract);
        // Provide printer settings
        settings = controller.parmReportContract().parmPrintSettings();
        settings.printMediumType(SRSPrintMediumType::File);
        settings.fileName(fileName);
        settings.fileFormat(SRSReportFileFormat::PDF);

        // Below is a part of code responsible for rendering the report
        controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
        controller.parmReportContract().parmReportExecutionInfo(executionInfo);

        srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
        srsReportRunService.preRunReport(controller.parmreportcontract());
        reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
        parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);

        srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
        // Actual rendering to byte array
        reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
                                              parameterValueArray,
                                              settings.fileFormat(),
                                              settings.deviceinfo());
    



        // You can also convert the report Bytes into an xpp BinData object if needed
        container binData;
        Binary binaryData;
        System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
        binaryData = Binary::constructFromMemoryStream(mstream);
       // System.IO.File::WriteAllBytes("C:\\backup\\"+fileName,reportBytes); // You can save the file on your local instance for verification
       

        if(binaryData)
        {
            binData = binaryData.getContainer();
        }
        Map map=new Map (Types::String,Types::String);
        map.insert("message","Its working fine for me");
        SLD_EmailAttachment::sendPDFEamilAttachment("EmailRecpt","en-us","ShaikhSohailHussain@gmail.com",map,binData,"P000173_AbcTest");
    }

}


USE following code to send as Email Attachment 



class SLD_EmailAttachment

{


  

    public static void sendPDFEamilAttachment( SysEmailId      _emailId,
        LanguageId      _language,
        SysEmailAddress             _emailAddr,
        Map             _mappings,container _binData,str _fileName)
    {
        SysEmailItemId                   nextEmailItemId;
        SysEmailTable                    sysEmailTable;
        SysEmailMessageTable             sysEmailMessageTable;
        SysEmailContents                 sysEmailContents;
        SysOutgoingEmailTable            outgoingEmailTable;
        SysOutgoingEmailData             outgoingEmailData;
        Filename filename, FileExtension;
      
        FileExtension=".pdf";
       
        select sysEmailTable
               join    sysEmailMessageTable
                where sysEmailMessageTable.EmailId==sysEmailTable.EmailId
                    && sysEmailMessageTable.EmailId== _emailId
                    && sysEmailMessageTable.LanguageId==_language;
       
        if(sysEmailTable.RecId>0)
        {
            sysEmailContents=SysEmailMessage::stringExpand(sysEmailMessageTable.Mail, _mappings);
            nextEmailItemId = EventInbox::nextEventId();
      
            filename =strFmt("%1_%2.pdf",nextEmailItemId,_fileName);
    
    
            outgoingEmailTable.clear();
            outgoingEmailTable.Origin=sysEmailTable.Description;
            outgoingEmailTable.EmailItemId = nextEmailItemId;
            outgoingEmailTable.IsSystemEmail = NoYes::Yes;
            outgoingEmailTable.Sender = sysEmailTable.SenderAddr;
            outgoingEmailTable.SenderName = sysEmailTable.SenderName;
            outgoingEmailTable.Recipient = _emailAddr;
            outgoingEmailTable.Subject = SysEmailMessage::stringExpand(sysEmailMessageTable.Subject, _mappings);
            outgoingEmailTable.Priority = eMailPriority::High;
            outgoingEmailTable.WithRetries = NoYes::NO;
            outgoingEmailTable.RetryNum = 0;
            outgoingEmailTable.UserId = curUserId();
            outgoingEmailTable.Status = SysEmailStatus::Unsent;
            outgoingEmailTable.Message =  sysEmailContents;
            outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
            outgoingEmailTable.TemplateId= _emailId;
            outgoingEmailTable.insert();


            if(conLen(_binData)>0)
            {
                outgoingEmailData.clear();

                outgoingEmailData.EmailItemId = nextEmailItemId;
                outgoingEmailData.DataId = 1;
                outgoingEmailData.EmailDataType = SysEmailDataType::Attachment;
                outgoingEmailData.Data = _binData;
                outgoingEmailData.FileName = filename;
                outgoingEmailData.FileExtension =FileExtension;

                outgoingEmailData.insert();
            }
        }
    }

}



Support Faryal's Cusine


Send Email in CC AX-2012


Send Email in CC AX-2012


Most of the developer have requirement in their project to send email in CC and in default Dynamics AX-2012 & D365FO this functionality is not available.


But there is the Standard class SysEmailDistributor which is responsible to send the complete AX emails.. we can achieve our goal and send email in CC as well..


Open the class and check the process method where you can find  object of SysMailerNet class.

 SysMailerNetAddressField tos,tocc;  // declare a variable <tocc>

 mailer = new SysMailerNet();  

 tocc=mailer.ccs();   // get the SysMailerNetAddressField  object using this method

tocc.add("ShaikhSohailHussain@gmail.com");  //add email address on which you want to send email as CC.



Please feel free to contact me if you are facing any issue during implementation of this blog

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...