6 Mayıs 2016 Cuma

AXAPTA - Sign function doesn't work correctly

Sign function doesn't work correctly in AX 2009 and 2012. It should returns -1 for negative numbers, 0 for zero and +1 for positive numbers. But  it gives -1 for negative and +1 for others.

Sign at Global:

static real sign(real num)
{
    return num >= 0 ? 1 : -1;
}


My correction:

static int sign(real num)
{

   if (num < 0)
    return -1;
   else
    return num > 0 ? 1 : 0;
}

5 Mayıs 2016 Perşembe

AXAPTA - Creating picking list

I created a class for me from found solution from a forum page :

class KRC_WMSOrder
{
    WMSShipment         wmsShipment;
    SalesTable          salesTable;
    WMSPickingRoute     wmsPickingRoute;
    WMSPickingRouteLink wmsPickingRouteLink;
    salesLine           salesLine;
}


void createOrderLine(Qty _qty = salesLine.RemainSalesPhysical)
{

    InventMovement                  inventMovement;
    WMSOrder                        wmsOrder;
    WMSOrderCreate                  orderCreate;
    WMSOrderTrans                   wmsOrderTrans;
    ;
    inventMovement = InventMovement::construct(salesLine);
    orderCreate = WMSOrderCreate::newMovement(inventMovement,_qty);
    orderCreate.parmMustBeWMSOrderControlled(true);
    orderCreate.parmQty(_qty);
    orderCreate.parmMaxQty(_qty);
    orderCreate.run();
    wmsOrder = orderCreate.parmWMSOrder();
    wmsOrder.updateShipment(wmsShipment,_qty, wmsPickingRoute.PickingRouteID);
}


void createWmsPickingRoute()
{
    ;
    wmsPickingRoute.clear();
    wmsPickingRoute.initTypeOrderPick(wmsShipment, WMSExpeditionStatus::Activated,
        WMSPickRequestTable::construct(salesTable),"", true);
    wmsPickingRoute.ActivationDateTime = DateTimeUtil::utcNow();
    wmsPickingRoute.insert();
}


void createWmsPickingRouteLink()
{
    ;
    wmsPickingRouteLink.clear();
    wmsPickingRouteLink.initFromSalesTable(salesTable);
    wmsPickingRouteLink.initFromWMSPickingRoute(wmsPickingRoute);
    wmsPickingRouteLink.insert();
}


void createWmsShipment()
{
    ;
    wmsShipment.clear();
    wmsShipment.initTypeOrderPick();
    wmsShipment.insert();
}


SalesLine  parmSalesLine(SalesLine _salesLine = salesLine)
{
    ;
    salesLine = _salesLine;
    return salesLine;
}


SalesTable  parmSalesTable(SalesTable _salesTable = salesTable)
{
    ;
    salesTable = _salesTable;
    return salesTable;
}


void reserveItem(Qty _qty = salesLine.RemainSalesPhysical)
{
    InventUpd_Reservation   invUpdReservation;
    ;
    invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(salesLine,InventMovSubType::None),
        salesLine.inventDim(),_qty,false);
    invUpdReservation.updateNow();
}


Sample usage:

KRC_WMSOrder            kWMS = new krc_wmsorder();
kWMS.createWmsShipment();
;
ttsbegin;
kWMS.parmSalesTable(salesTable);
kWMS.createWmsPickingRoute();
kWMS.createWmsPickingRouteLink();
kWMS.parmSalesLine(salesLine);
kWMS.reserveItem();
kWMS.createOrderLine();

ttscommit;

AXAPTA - How to disable auto filter in a form came with args parameter

I found the solution from a forum page :


KRC_PlanWaves_DS.query().dataSourceNo(1).clearDynalinks();

24 Mart 2016 Perşembe

AXAPTA - Solve of turkish letter problem when send mail with sysmailer class

I found this solution from a blog which I cannot remember. Turkish letters (or another special letters with some languages) will not shown when send mail with sysMailer class if you won't add this red line:


   SysEmailParameters  parameters;
    SysMailer           mailer;
    ;
    new InteropPermission(InteropKind::ComInterop).assert();
        parameters = SysEmailParameters::find();

        mailer = new SysMailer();
        if (parameters.SMTPRelayServerName)
        {
            mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
                               parameters.SMTPPortNumber,
                               parameters.SMTPUserName,
                               SysEmailParameters::password(),
                               parameters.NTLM);
        }
        else
        {
            mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
                               parameters.SMTPPortNumber,
                               parameters.SMTPUserName,
                               SysEmailParameters::password(),
                               parameters.NTLM);
        }
        mailer.fromAddress(fromAddr);
        mailer.tos().appendAddress(toAddr);
        mailer.subject(subject);
        //solution for turkish letter problem (ÖöÇçĞğÜüŞşİı):
        mailer.bodyCharSet("Windows-1254");
        if(FileName)
            mailer.attachments().add(FileName);
        mailer.ccs().appendAddress(ccAddr);
        mailer.bccs().appendAddress(bccAddr);
        mailer.htmlBody(body);
        mailer.sendMail();
    }
    CodeAccessPermission::revertAssert();

2 Mart 2016 Çarşamba

AXAPTA - Find a table fields label value

There are two ways to find a table field's label value:

If fields label value derived from directly fields extended data type:
 
    if (curext()=="krc" && this.RBOInventItemGroupId == "")
        ret = checkfailed(strfmt("'%1' field cannot be empty!..",
            new SysDictType(extendedTypeNum(RBORetailGroupId)).label()));

If there is a special label value dedicated at table level:

    if (curext()=="krc" && this.RBOInventItemGroupId == "")
        ret = checkfailed(strfmt("'%1'
field cannot be empty!..",
            new SysDictField(tablenum(WholeSalesCampaignGroup),
fieldnum(WholeSalesCampaignGroup,RBOInventItemGroupId)).label()));
 

5 Şubat 2016 Cuma

AXAPTA - Prevent user to change filter from grid header

SysQuery::findOrCreateRange(InventDim_DS.query().dataSourceTable(tablenum(InventDim)),fieldnum(InventDim,InventSiteId)).status(RangeStatus::Locked);

26 Ocak 2016 Salı

AX 2009 - Run report at back ground as PDF output

Make Interactive property of report as No. It's easy make it as run for html with change  PrintMedium enum's value.

     DocuType                docuType;
    TextIo                  textIo;
    FileIOPermission        fioPermission;
    #File
    ReportRun report;
    ;

    docuType = DocuType::find("Temp");
    fileName = strfmt(@"%1My Test Report.PDF",   docuType.ArchivePath);
   
    fioPermission = new FileIOPermission(fileName ,"RW");
    fioPermission.assert();

    if(Global::isRunningOnServer())
    {
        if(WinAPIServer::fileExists(fileName))
            WINAPIServer::deleteFile(fileName);
    }
    else
    {
        if(WinAPI::fileExists(fileName))
            WINAPI::deleteFile(fileName);
    }

    report = new ReportRun(new  Args(ReportStr(KRC_InventCoverReport)));
    report.printJobSettings().setTarget(PrintMedium::File);
    report.printJobSettings().preferredTarget(PrintMedium::File);
    report.printJobSettings().format(PrintFormat::PDF);
    report.printJobSettings().fileName(fileName);
    report.query().interactive(false);
    report.run();