Monday, 19 August 2019

Generate report through X++ and save as pdf in to folder EX:SalesInvoiceReport +D365


SrsReportRunController   controller = new SrsReportRunController();

        SalesInvoiceContract     rdpContract = new SalesInvoiceContract();
        SRSPrintDestinationSettings   settings;
        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();
        ;
        CustInvoiceJour custInvoiceJour = CustInvoiceJour::findFromSalesId_IN("SO081204");
        if(custInvoiceJour)
        {
            if (!WinAPI::pathExists("C:\\Temp\\Invoices\\"))
                WinAPI::createDirectoryPath("C:\\Temp\\Invoices\\");

            Filename filename =strfmt("C:\\Temp\\Invoices\\%1%2",custInvoiceJour.InvoiceId,".pdf");

            controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
            controller.parmShowDialog(false);// Explicitly provide all required parameters
            rdpContract.parmRecordId(custInvoiceJour.RecId);
            controller.parmReportContract().parmRdpContract(rdpContract);// Change print settings as needed
            settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::File);
            settings.fileFormat(SRSReportFileFormat::PDF);
            settings.overwriteFile(true);
            settings.fileName(filename);
            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());

            if (reportBytes)
            {
                System.IO.Stream            stream         = new System.IO.MemoryStream(reportBytes);
                var fileStream = new System.IO.FileStream(filename, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
                stream.CopyTo(fileStream);

            }
        }


==========================================================================
http://www.dnetsoft.com/en-us/d365-generate-a-report-through-x-and-save-in-a-local-folder/

Tuesday, 13 August 2019

XPO Interface

https://app.swaggerhub.com/apis-docs/xposc/FulfillmentServicesGateway/1.0.0#/Shipment/createShipment

Friday, 2 August 2019

Listpage Interaction class

1. Change Properties form control from listpage class example code.

public void initializeQuery(Query _query)
{
    // ListPageLabelChange =>
    Common              externalRecord;
    FormDataSource      frmDs;
    FormRun             formRun;
    FormControl         frmCtrl;
    // ListPageLabelChange <=
     
    _query.dataSourceTable(tableNum(HRSBenefitEntitlement)).addRange(fieldNum(HRSBenefitEntitlement,Employment)).value(SysQuery::value(HcmEmployment::findByWorkerLegalEntity(HcmWorker::userId2Worker(curUserId()),CompanyInfo::find().RecId).RecId));
     
    super(_query);
     
     // ListPageLabelChange =>
    externalRecord = this.listPage().activeRecord(_query.dataSourceTable(tableNum(HRSBenefitEntitlement)).name());//No intrisic function for form DS?
    if(externalRecord.isFormDataSource())
    {
        frmDs   = externalRecord.dataSource();
        formRun = frmDs.formRun();
        if(formRun)
        {
            frmCtrl = formRun.design().controlName(formControlStr(TIDBenefitEntitlementListPage,HRSBenefitEntitlement_Entitlement));
            if(frmCtrl)
            {
                frmCtrl.userPromptText("newName");
            }
        }
    }
    // ListPageLabelChange <=
}

Thursday, 1 August 2019

Using the class DimensionProvider to filter a query with multiple financial dimensions criteria


https://axforce.wordpress.com/2015/12/07/using-the-class-dimensionprovider-to-filter-a-query-with-multiple-financial-dimensions-criteria/


static void EDC_dimensionProvider(String10 _depvalue)
{
    #define.dimAttr("Department")
    #define.dimRangeValue("79")

    Query query = new Query();
    QueryRun queryRun;
    QueryBuildDataSource queryCustTable;
    QueryBuildRange queryDimRange;
    string255   purchid;

    PurchLine purchline;
    DimensionProvider dimensionProvider;

    DimensionAttributeValueSetStorage dimAttrValueSetStorage;
    int countLine = 1;
    int i;
    container conpurchid;
    queryCustTable = query.addDataSource(tableNum(PurchLine));
    dimensionProvider = new DimensionProvider();

    dimensionProvider.addAttributeRangeToQuery(
        query,
        queryCustTable.name(),
        identifierStr(DefaultDimension),
        DimensionComponent::DimensionAttribute,
        #dimRangeValue,
        #dimAttr,
        true);

    queryRun = new QueryRun(query);

    while (queryRun.next()) {
        purchline = queryRun.get(tableNum(PurchLine));

        dimAttrValueSetStorage = DimensionAttributeValueSetStorage::find(purchline.DefaultDimension);

        for (i = 1; i <= dimAttrValueSetStorage.elements(); i++) {
            if(DimensionAttribute::find(dimAttrValueSetStorage.getAttributeByIndex(i)).Name == "Department")
            {
                if(confind(conpurchid, purchline.PurchId))
                    conpurchid = conIns(conpurchid,i,purchline.PurchId);
                info(strFmt("PurchId %1:%2: %3",
                    purchline.PurchId,
                    DimensionAttribute::find(dimAttrValueSetStorage.getAttributeByIndex(i)).Name,
                    dimAttrValueSetStorage.getDisplayValueByIndex(i)));
            }
        }
    }

}