Microsoft Dynamics AX development

PurchFormLetter  purchFormLetter
ProductReceiptId productReceiptId;
PurchLine        purchLine;
PurchTable       purchTable = PurchTable::find('123456');
PurchQty         purchQty = 20;

while select purchLine
where purchLine.PurchId == purchTable.PurchId
&& purchLine.IsDeleted == NoYes::No
{
purchLine.PurchReceiveNow = purchQty;
purchLine.setInventReceiveNow();
purchLine.update();
}

purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchTable, productReceiptId, purchFormLetter.transDate(), PurchUpdate::ReceiveNow);
purchTable.reread();

PurchFormLetter purchFormLetter
PurchTable purchTable = PurchTable::find('123456');
PackingSlipId packingSlipId = 'PS_01';

purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, packingSlipId);
purchTable.reread();

To keep table groups on the same page, the table group should look like this:

Aufnahme1

Then, select the group row and set the properties “KeepTogheter” to True.

Aufnahme2

Deploy the report.

 

Align image logo to the right

1) In the DP class find the width of the image:

Image img = new Image();
CompanyInfo companyInfo = CompanyInfo::find();
CompnayImage companyImage = CompnayImage::findByRecord(comapnyInfo);

img.setData(companyImage.Image);

salesPackingSlipHeaderTmp.LogoWidth = img.Width();

2) Add the image to the report:

2

3) Set the parameters to take the image from the dataset:

3

4) In Visual Studio set the Size property (of the image) to “Original size” (Right click on the image > Properies > Size)

5) Add the following expression in the “padding left” expression:

=CSTR(211-First(Fields!LogoWidth.value, “DataSetName”)) + “pt”

Where 211 is the maximum size (in pixel) of the image.

5
6) Deploy the report

To export data to an excel file, we can use the SysExcelWorksheetHelper.
Here an example:

static void exportExcelFile(Args _args)
{
    SysExcelApplication     xlsApplication;
    SysExcelWorkBooks       xlsWorkBookCollection;
    SysExcelWorkBook        xlsWorkBook;
    SysExcelWorkSheets      xlsWorkSheetCollection;
    SysExcelWorkSheet       xlsWorkSheet;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelHelper          sysExcelHelper;
    VendRFQJour             vendRFQJour;
    int                     row = 1;
    str                     fileName;
    str                     worksheetName;
    Date                    deliveryDate;

    fileName    = "Path\\Test.xlsx";

    vendRFQJour = VendRFQJour::find("000103");

    worksheetName = "Worksheet name";
    sysExcelHelper = SysExcelHelper::construct();
    sysExcelHelper.initialize();
    xlsWorkSheet = sysExcelHelper.addWorksheet(worksheetName);

    worksheetHelper = SysExcelWorksheetHelper::construct(xlsWorkSheet);

    worksheetHelper.addColumn(1, 'RFQ Id', Types::String);
    worksheetHelper.addColumn(2, 'Delivery date', Types::Date);

    worksheetHelper.setCellValue(1, row, 'RFQId');
    worksheetHelper.setCellValue(2, row, 'DeliveryDate');
    row++;

    worksheetHelper.setCellValue(1, row, vendRFQJour.RFQId);
    worksheetHelper.setCellValue(2, row, vendRFQJour.DeliveryDate);

    if(WinApi::fileExists(fileName))
        WinApi::deleteFile(fileName);

    sysExcelHelper.save(filename);
    sysExcelHelper.close();

    info(strFmt("Creato file: %1", fileName));
}

During the import of the contact person, an additional address is always created.
If, in the file, there isn’t an address, the DIEF creates an empty address.

To avoid the problem, we must to insert an additional if clause in the DMFContactPersonEntityClass, method GeneratePostalAddress:

public container GeneratePostalAddress(boolean _stagingToTarget = true)
{
    container res;

    if (_stagingToTarget && entity.Address) //additional if
        res = DMFLogisticsAddressHelper::GeneratePostalAddressGlobal(entity, target, party, partyRecId,this.getRoleSeparator(), true, _stagingToTarget);

    if (_stagingToTarget)
    {
        res = conNull();
    }

    return res;
}

Goal: print the logo only if the print destination is the printer

First of all we need a parameter, and we declare it in the contract class as follow:

[DataMemberAttribute('printLogo')]
public boolean parmPrintLogo(UsePrintMgmt _printLogo = printLogo)
{
    printLogo = _printLogo;
    return printLogo;
}

Then, we must to modify the code of the report controller. The controller must extend the SrsPrintMgmtFormLetterController or a subclass of this.

The method to override is: SrsPrintMgmtController.outputReport()
This method executes the report for the print management setting that is currently loaded.

In this way, for every record in the print management, we control the print destination, and consequently we set the parameter for the logo visibility.

protected void outputReport()
{
    SalesConfirmContract salesConfirmContract = contract as SalesConfirmContract;

    switch (formLetterReport.getCurrentPrintSetting().parmPrintJobSettings().printMediumType())
    {
        case SRSPrintMediumType::Printer : salesConfirmContract.parmPrintLogo(NoYes::No);
        break;

        default : salesConfirmContract.parmPrintLogo(NoYes::Yes);
        break;
    }

    super();
}

If the logo visibility, depend on the type of the PrintCopyOriginal, the code to use is the following:

protected void outputReport()
{
    SalesConfirmContract salesConfirmContract = contract as SalesConfirmContract;
    switch (formLetterReport.getCurrentPrintSetting().parmType())
    {
        case PrintMgmtDocInstanceType::Copy :
	salesConfirmContract.parmPrintLogo(NoYes::No);
        break;

        case PrintMgmtDocInstanceType::Original :
	salesConfirmContract.parmPrintLogo(NoYes::Yes);
        break;
    }
    super();
}

Now, we have to use the new parameter in the report layout. We found the parameter here:
parameter

Finally, insert the following code in the layout, in the “Visibility” property on the image.
Aufnahme2

Tag Cloud