21 June 2022

Email the attachments using x++ code in D365FO via SysMailerMessageBuilder, multiple attachments

 class EmailJob

{


    public static void main(Args _args)

    {

        DocuRef     docuRef;

        DocuType    docuType;

        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();

        Email   toEmail;

        Email   fromEmail;

        SysEmailSystemTable emailSystemTable = SysEmailSystemTable::find("WFEMAIL"); //  system email template email id.

        SysEmailMessageTable sysEmailMessageTable = SysEmailMessageTable::find(emailSystemTable.EmailId, emailSystemTable.DefaultLanguage);       

         

        try

        {

            FromEmail = emailSystemTable.SenderAddr;//"abc@3ELogistics.onmicrosoft.com";

            toEmail   = "to@gmail.com";


            messageBuilder.setBody("Hello from D365", false);

            messageBuilder.setSubject("Email Test from D365");

            messageBuilder.addTo(toEmail);

            // Note: not calling setFrom() defaults to the current user for SMTP client, whereas

            // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used

            messageBuilder.setFrom(fromEmail);


            while select docuRef

                where   docuRef.RefCompanyId    == curExt()

                && docuRef.RefTableId           == tableNum(CustInvoiceTable)

                && docuRef.RefRecId      == 5637151326 // CustInvoiceTable.recId

            Exists join docuType

                where docuType.typeId == docuRef.TypeId

                && docuType.TypeGroup == docuTypeGroup::File

            {

                messageBuilder.addAttachment(DocumentManagement::getAttachmentStream(docuRef),docuRef.Name + '.pdf');

            }

            SysMailerFactory::sendInteractive(messageBuilder.getMessage());

            // Try using sendNonInteractive method too

        }

        catch (Exception::Error)

        {

            throw error("@SYS33567");

        }

    }


}

26 May 2022

Getting Dimension value and description from default dimension in D365FO

 DefaultDimensionView    defaultDimensionView;

    
    select defaultDimensionView
        where defaultDimensionView.DefaultDimension == _defualtDimension//recId
        && defaultDimensionView.Name == 'CostCenter';    

    info(defaultDimensionView.displayvalue);
info(defaultDimensionView.dimensionDiscription());

============================================================

DefaultDimensionView dimensionView;
        DimensionAttribute dimensionAttribute;

        select firstOnly dimensionView
            where dimensionView.DefaultDimension == 5637146834
        join dimensionAttribute
            where dimensionView.Name == dimensionAttribute.Name
            && dimensionView.Name == 'Costcenter';

        info(dimensionView.DisplayValue);

        info(strFmt("Display value= %1",dimensionView.dimensionDiscription()));

04 April 2022

How to get the selected query range value in AX 2012 and D365FO

 QueryBuildRange accountRange;

accountRange = qbd.findRange(fieldNum(VendTable, AccountNum)); if (accountRange) { info(accountRange.value()); }

24 March 2022

COC ,Access to another data source from data source method on form

  FormDataSource     salesLine_ds = this.formRun().dataSource(formDataSourceStr(SalesTable, salesLine));

        SalesLine salesLine = salesLine_ds.cursor();

29 January 2022

How to get sales order delivery postal address Phone ,street in D365FO

 LogisticsPostalAddress deliveryPostalAddress = LogisticsPostalAddress::findRecId(salesTable.DeliveryPostalAddress);

deliveryPostalAddress.City;                   

 deliveryPostalAddress.State;

            

10 January 2022

How to get product variants in D365FO using X++

  public EcoResProductDisplayProductNumber getProductVariants(SalesLine _saleLine)

    {

        InventDimCombination            inventDimCombination  = InventDimCombination::findVariantId(_saleLine.RetailVariantId);

        InventDim                       inventDim;

        InventDistinctProductExpanded   inventDistinctProductExpanded;


        select inventDistinctProductExpanded

            where inventDistinctProductExpanded.ItemId == _saleLine.ItemId

            && inventDistinctProductExpanded.InventDimId == inventDimCombination.InventDimId;


        return inventDistinctProductExpanded.DisplayProductNumber;

    }

26 November 2021

Try catch exception example in D365FO

 class TestClass

{

    public static void main(Args args)

    {

        PurchTable purchTable;

        

        System.Exception ex;

        

            //Counter cnt = 1;

            while select purchTable

            {

                try

                {

                    //doing updation on  the purchatable.

                }


                catch(ex)

                {

                    System.String messageEx = ex.Message;

                    warning(strFmt("There is an error%1",messageEx));                    

                }

            }

        

       

    }


}

Service class to get the selected record and deleted matching records and refresh the form data source in D365 F&O

 [DataContractAttribute] class ABCUserProfilesBulkDeleteContract {         UserId userId;     [DataMemberAttribute('UserId')]     pu...