Wednesday, January 19, 2022

Computed column view method with T-SQL statement in D365FO

 Converting to view computed column method.

T-SQL statment like this way.

return strFmt(@'select top 1 WHT.ACCOUNTNUM from WHSSHIPMENTTABLE as WHT

                           where WHT.WaveId = %1 order by WHT.RECID asc',waveId);

Sunday, January 16, 2022

Convert word stream to PDF file X++ in D365FO

 using AK = Microsoft.Dynamics365.LocalizationFramework.MicrosoftInternalUseOnly.ApiKeys;

using GR = Microsoft.Dynamics365.LocalizationFramework.Repositories.GlobalRepository;

using Microsoft.Dynamics365.LocalizationFramework;

using TL = Microsoft.Dynamics365.LocalizationFramework.Telemetry;

using BCS = Microsoft.Dynamics365.LocalizationFramework.ExternalApi.BCS;

using EA = Microsoft.Dynamics365.LocalizationFramework.ExternalApi;

using Microsoft.Dynamics.ApplicationPlatform.Environment;

using Microsoft.Dynamics.ApplicationPlatform.Environment.Settings;

using Microsoft.Dynamics.AX.Security.AuthenticationCommon;

using Microsoft.Dynamics.AX.Security.ADALClientAuthentication;

using Microsoft.Dynamics.AX.Framework.FileManagement;

class WordToPDFConverter 

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>


    public static void main(Args _args)

    {

        System.IO.Stream inputStream; //word stream

        str fileExtension = '.docx';

        System.IO.Stream outputPDFStream; //Pdf stream

        System.IO.Stream    fileStream;

        try

        {

            fileStream  = File::UseFileFromURL('C:\\wordfile\\word1.docx');

        }

        catch

        {

            warning("File not found");

        }

        inputStream =  fileStream;

        BCS.ConvertToPdfRequest request = new BCS.ConvertToPdfRequest();

        BCS.ConvertToPdfResponse response;


        request.FileStream = inputStream;

        request.ClientCorrelationId = newGuid();

        request.ClientName = identifierStr(DynamicsAxElectronicReporting);

        request.FileExtension = fileExtension;


        var ret = new BCS.PdfConversionPageOptions();

        ret.Orientation = BCS.PdfConversionPageOrientation::Portrait;


        request.PageOptions = ret;

        request.LocaleIdentifier = 0;


        AK.IApiKeysProviderService apiKeysProvider = null;

        Microsoft.Dynamics.Client.ServerForm.Contexts.SessionContext sessionContext;

        System.Uri currentUrl = null;

        sessionContext = Microsoft.Dynamics.Client.ServerForm.Contexts.SessionContext::get_Current();

        if (sessionContext)

        {

            currentUrl = sessionContext.get_RequestUrl();

        }

        str ProdUrl = 'https://apikeys.configure.global.dynamics.com';

        System.String configValue = System.Configuration.ConfigurationManager::AppSettings.Get('RCS.GlobalRepoKeysAPIUrl');

        var configProvider = System.String::IsNullOrEmpty(configValue) ? ProdUrl : configValue;

        str authProvd = ERParameterTable::find().RCSApplicationAADUrl;

        if (!authProvd)

        {

            authProvd = (ERParameterTable::isMooncake() ? 'https://configure.global.dynamics.cn' : 'http://configure.global.dynamics.com');

        }

            var s2SAuthProvider = new GR.S2SAuthenticationProvider(authProvd);

            apiKeysProvider = new GR.MicrosoftInternalUseOnly.GlobalRepositoryApiKeysClient(s2SAuthProvider, configProvider);

            var provider = apiKeysProvider;

            var conversionClient = EA.BCS.BcsApiClient::Instance;

            response =  conversionClient.ConvertToPdf(request, provider, TL.ElectronicReportingMappingTelemetryLogger::Log);

            if (response.IsValidResponse)

            {

                outputPDFStream = response.ResultStream;

                File::SendFileToUser(outputPDFStream,'word1.pdf');

            }        

    }

}


Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...