get product-category Descendants example

public FreeText getDecendants(ItemId _itemid)
{
    str Decendants;
    EcoResProductCategory ecoResProductCategory;
    EcoResCategory        ecoResCategory;

    EcoResCategory        ecoResCategoryAscendants;

    select firstOnly ecoResProductCategory
    where
        ecoResProductCategory.Product==EcoResProduct::findByProductNumber(_itemid).RecId;

    select firstOnly ecoResCategory where ecoResCategory.RecId==ecoResProductCategory.Category;
    Decendants = ecoResCategory.Name;
    while select * from ecoResCategoryAscendants
            order by ecoResCategoryAscendants.NestedSetRight
                where   ecoResCategoryAscendants.CategoryHierarchy == EcoResCategory.CategoryHierarchy
                        && ecoResCategoryAscendants.NestedSetLeft  < EcoResCategory.NestedSetLeft
                        && ecoResCategoryAscendants.NestedSetRight > EcoResCategory.NestedSetRight
    {
       Decendants = strFmt("%1-%2",ecoResCategoryAscendants.Name,Decendants);
    }


    return Decendants;
}

call Manager Authentication Form for AX Retail POS

add reference library InteractionDefault.dll.

use this code below :

using Microsoft.Dynamics.Retail.Pos.Interaction

ManagerAccessForm formManager = new ManagerAccessForm();
var cekDialog = formManager.ShowDialog();
if (cekDialog == DialogResult.OK)
{
   // your logic
}

and dont forget to set ManagerAccessForm() to public on InteractionDefault project.

public ManagerAccessForm()
{
   InitializeComponent();
}

using “update_record” instead of “while select forupdate”

description on MSDN :
“This means that certain tasks may have improved performance by using the power of the SQL server.”

replace code below for a better perfomance.

MyTable myTableBuffer;
;
while select forUpdate mytableBuffer
{
mytableBuffer.field1 = field * 1.10;
}

with


MyTable myTableBuffer;
;
update_recordset myTableBuffer
setting field1 = field1 * 1.10;

source : http://msdn.microsoft.com/en-us/library/aa674382.aspx

How to print barcode Label , SSRS can’t print on Landscape Printer AX 2012r2

Hi there ,
after the report being save to PDF on local drive, i call adobe to print barcode,
i have to did that, because SSRS can’t print on landscape printer.

here is my example code

void clicked()
{
    //AIFD_PrintBarcode
    AI_PrintBarcodeController  aiBarcode = new AI_PrintBarcodeController();
    AI_PrintBarcodeContract    aiContract = new AI_PrintBarcodeContract();
    ProdJournalProd            prodJournalProdLoc;
    SRSPrintDestinationSettings  printSettings = new SRSPrintDestinationSettings();
    PrintJobSettings    printJobSettings = new PrintJobSettings();
    Dialog              dialog = new Dialog();
    DialogField         dialogFileName;
    str                 adobeExe;
    str                 adobeParm;

    str                 fileName;
    int                 fileCount;

    //AIFD
    InteropPermission   permission;
    str errorMessage;
    //END
    real WeightInreal;
    permission = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();

    super();
    try
    {
        prodJournalProdLoc = ProdJournalProd_ds.getFirst(true);

        while (prodJournalProdLoc)
        {
            fileCount++;
            aiBarcode.parmReportName(ssrsReportStr(AI_PrintBarcoderReport,Report));
            aiBarcode.parmShowDialog(false);
            aiContract.parmRecordId(prodJournalProdLoc.RecId);
            aiContract.parmDocumentTitle(&quot;x&quot;);

            //printSettings = aiBarcode.parmReportContract().parmPrintSettings();
            printSettings.printMediumType(SRSPrintMediumType::File);
            //printSettings.landscape(false);
            //printSettings.printerPageSettings('KRRLabelBarcode');
            //info(strFmt(&quot;%1&quot;,printSettings.printerPageSettings()));

            fileName = strFmt(&quot;D:\\barcode%1.pdf&quot;,fileCount);

            printSettings.fileFormat(SRSReportFileFormat::PDF);
            printSettings.fileName(fileName);
            printSettings.printerName(&quot;TOSHIBA B-SA4TP TS&quot;);
            printSettings.landscape(false);
            printSettings.overwriteFile(true);
            aiBarcode.parmReportContract().parmRdpContract(aiContract);
            aiBarcode.parmReportContract().parmPrintSettings(printSettings);

            aiBarcode.startOperation();

            WeightInReal = sleep(500);
            //printJobSettings.printerSettings('SysPrintForm');
            printJobSettings.setTarget(PrintMedium::Printer);
            printJobSettings.preferredTarget(PrintMedium::Printer);
            adobeExe = WinAPI::findExecutable(fileName);

            adobeParm = strFmt(' /t &quot;%1&quot; &quot;%2&quot; &quot;%3&quot; &quot;%4&quot;',
                               fileName,
                               &quot;TOSHIBA B-SA4TP TS&quot;,
                               printJobSettings.printerDriverName(),
                               printJobSettings.printerPortName());

            winAPI::shellExecute(adobeExe,  adobeParm);

            WeightInReal = sleep(500);

            prodJournalProdLoc = ProdJournalProd_ds.getNext();
         }
     CodeAccessPermission::revertAssert();
    }
    catch(Exception::CLRError)
    {
        errorMessage = AifUtil::getClrErrorMessage();

        CodeAccessPermission::revertAssert();

        throw error(errorMessage);
    }
    //END
}

Custom lookup example code x++ AX 2012

Example of custom lookup for itemid on PurchLine , form : PurchTable

public void lookup()
{
 SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);
 Query query = new Query();
 QueryBuildDataSource queryBuildDataSource, queryBuildDataSource2;
 QueryBuildRange queryBuildRange, queryBuildRange2;
 QueryBuildLink queryBuildLink;
 BuyBackScheme BuyBackScheme;
 str FilterCategory;
 //super();

 queryBuildDataSource = query.addDataSource(tablenum(InventTable));
 //add by Fanddy
 if(InventBuyerGroup::find(PurchTable.ItemBuyerGroupId).InventOwnership == InventOwnership::MD)
 {
 queryBuildDataSource = queryBuildDataSource.addDataSource(tableNum(PdsApprovedVendorList));
 queryBuildDataSource.joinMode(JoinMode::InnerJoin);
 queryBuildDataSource.relations(true);

 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,PdsApprovedVendor)).value(PurchTable.OrderAccount);
 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,ValidFrom)).value(strFmt(“&lt;= %1″,DateTimeUtil::date(DateTimeUtil::removeTimeZoneOffset(PurchTable.createdDateTime,TimeZone::GMTPLUS0700_BANGKOK_HANOI_JAKARTA))));
 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,ValidTo)).value(strFmt(“&gt;= %1″,DateTimeUtil::date(DateTimeUtil::removeTimeZoneOffset(PurchTable.createdDateTime,TimeZone::GMTPLUS0700_BANGKOK_HANOI_JAKARTA))));

 }
 //END by fandd

 sysTableLookup.addLookupfield(fieldnum(InventTable, itemId));
 sysTableLookup.addLookupMethod(‘itemName’);
 sysTableLookup.addLookupMethod(‘itemGroupId’);
 sysTableLookup.addLookupfield(fieldnum(InventTable, NameAlias));
 sysTableLookup.addLookupMethod(tableMethodStr(InventTable,pdsDefaultOrderType));
 sysTableLookup.addLookupfield(fieldnum(InventTable, RetailType));
 sysTableLookup.parmQuery(query);
 sysTableLookup.performFormLookup();

}

happy daxing !

 

Create BOM Journal example via x++ AX 2012

 

static void createMovJournal(Args _args)
{
  InventJournalTable  journalTable;
  InventJournalTrans  journalTrans;
  JournalId           journalId;
  CustomReportFinishedConvertItem    convertItem;
  InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
  ;

  // Init JournalTable

  journalTable.clear();
  journalTable.initValue();
  journalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().BomJournalNameId));
  journalId = NumberSeq::newGetNum(InventParameters::numRefInventJournalId()).num();
  journalTable.JournalId = journalId;
  journalTable.insert();

  journalTrans.clear();
  journalTrans.initFromInventJournalTable(journalTable);
  journalTrans.initFromInventTable(InventTable::find(convertItem.ItemIdChild));
  journalTrans.InventDimId = convertItem.InventDimId;
  journalTrans.Qty = convertItem.Qty;
  journalTrans.PriceUnit        = InventTableModule::find(journalTrans.ItemId, ModuleInventPurchSales::Invent).pcsPrice();
  journalTrans.CostAmount       = journalTrans.Qty * journalTrans.PriceUnit;
  journalTrans.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
  journalTrans.TransDate = today();
  journalTrans.Voucher = NumberSeq::newGetNumFromId(journalTable.VoucherNumberSequenceTable).num();
  journalTrans.BOMLine = NoYes::No;
  journalTrans.insert();

  inventTransId    = journalTrans.InventTransId;

  journalTrans.clear();
  journalTrans.initFromInventJournalTable(journalTable);
  journalTrans.initFromInventTable(InventTable::find(convertItem.ItemId));
  journalTrans.InventDimId = convertItem.InventDimIdRAF;
  journalTrans.Qty = -1*convertItem.QtyConversion;
  journalTrans.PriceUnit        = InventTableModule::find(journalTrans.ItemId, ModuleInventPurchSales::Invent).pcsPrice();
  journalTrans.CostAmount       = journalTrans.Qty * journalTrans.PriceUnit;
  journalTrans.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
  journalTrans.TransDate  = today();
  journalTrans.Voucher = NumberSeq::newGetNumFromId(journalTable.VoucherNumberSequenceTable).num();
  journalTrans.BOMLine = NoYes::Yes;
  journalTrans.InventTransIdFather =  inventTransId;
  journalTrans.insert();
  //end edited by fanddy


  // Call the static method to post the journal
  if(InventJournalCheckPost::newPostJournal(journalTable).validate())
  InventJournalCheckPost::newPostJournal(journalTable).run();

}

source :

1.http://www.andesoft.net/creating-bom-journal-using-x-code-ax-2009-ax-2012/

2.http://learnax.blogspot.com/2010/01/x-code-to-create-and-post-inventory.html

get last WorkFlow Comment. AX 2012

just add this code to tables method and drag it to the grid

display public server str aiComment()
{
WorkflowTrackingStatusTable trackingStatusTable;
WorkflowTrackingTable trackingTable;
WorkflowTrackingCommentTable trackingCommentTable;
WorkflowComment commentLoc = “”, comment;
;

while select trackingStatusTable where trackingStatusTable.ContextRecId == this.RecId join trackingTable
where trackingTable.WorkflowTrackingStatusTable == trackingStatusTable.RecId join trackingCommentTable
where trackingCommentTable.WorkflowTrackingTable == trackingTable.RecId && trackingCommentTable.Comment != commentLoc
{
comment = trackingCommentTable.Comment;
}

return comment;
}

by : _fiant

one PurchReq Line multiple PO

got client that really what one PR line can posting to multiple.

class RequisitionReleaseStrategy\Main

add this code below

//AIFD
if(cekProses)
{
    ttsBegin;
    for (purchReqLine = fds.getFirst(processMarkedRows) ? fds.getFirst(processMarkedRows) : _args.record(); purchReqLine; purchReqLine = fds.getNext())
    {
        select forUpdate purchReqLineLoc where purchReqLineLoc.RecId==purchReqLine.RecId;
        purchReqLineLoc.PurchLineCreated = false;
        purchReqLineLoc.RequisitionStatus = PurchReqRequisitionStatus::Approved;
        if(purchReqLineLoc)
        {
            purchReqLineLoc.update();
        }
    }
    ttsCommit;
}

Query based Report , add parameter dateFrom and dateTo//

//your language script here
[SysEntryPointAttribute(false)]
public void processReport()
{
    Query q;
    QueryRun qr;
    TransDate dateTo,dateFrom;

    AITransporterPerformanceReportContract contract = this.parmDataContract() as AITransporterPerformanceReportContract;

    dateTo = contract.parmDateTo();
    dateFrom = contract.parmDateFrom();

    delete_from aiTmp;
    q = this.parmQuery();
    q.dataSourceTable(tablenum(CustPackingSlipJour)).addRange(fieldnum(CustPackingSlipJour, DeliveryDate)).value(queryRange( dateFrom, dateTo));
    qR = new QueryRun(q);
    while(qR.next())
    {
        // your logic
    }
}

Vendor or Customer , Invoicing or Delivery Address

display Addressing  InvoicingAddress()
{
    Addressing address;
    DirPartyRecId party;
 
    party = CustTable::find(custConfirmJour.InvoiceAccount).Party;
    address = DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Invoice);
 
    if (!address)
        address = DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Delivery);
 
    return address;
}

source : http://dynamicsuser.net/forums/t/56107.aspx

Column BackColor Grid Form AX 2012

override method displayOptions in gridForm.

public void displayOption(Common _record, FormRowDisplayOption _options)
{
   #define.Red(255,0,0)
   TableNameDataSource   tableNameLoc;

   tableNameLoc = _record.data();

   //your logic if while etc
    
   _options.backColor(WinAPI:RGB2int(#Red);
   _options.affectedElementsByControl(element.controlId(CONTROL_NAME_IN_FORM));
   
   super(_record,_options);
   
}

contributor : _le

Print Sales Invoice via job X++ ax 2012

protected void printReportPdf(Common _record)
{
    args args = new args();
    CustInvoiceJour custInvoiceJour = _record;
    SRSPrintDestinationSettings printSettings;
    SalesInvoiceController controller = new SalesInvoiceController();

    args.record(_record);

    pdfPath = WinAPI::getTempPath() + custInvoiceJour.InvoiceId + ".pdf";

    // imposta nome report
    controller.parmReportName(ssrsReportStr(SalesInvoice, Report));

    // get print settings from contract
    printSettings = controller.parmReportContract().parmPrintSettings();

    // set print medium
    printSettings.printMediumType(SRSPrintMediumType::File);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.overwriteFile(true);
    printSettings.fileName(pdfPath);

    // forzo che non vengano cambiati i parametri di stampa che gli passo io
    controller.DEVparmLockDestinationProperties(true);

    // suppress the parameter dialog
    controller.parmShowDialog(false);
    controller.parmArgs(args);

    // start operation
    controller.startOperation();
}

source : http://daxldsoft.blogspot.com/2012/07/print-salesinvoice-packingslip-or.html

print Sales Picking List via Jobs X++ AX 2012

static void Job6(Args _args)
{
    WMSPickingRoute         wmsPickingRoute;
    WmsPickingList_OrderPickController  aiController = new WmsPickingList_OrderPickController();
    WmsPickingList_OrderPickContract    aiContract   = new WmsPickingList_OrderPickContract();
    SRSTmpDataStore                     srsTmpDataStore;
 
    select firstOnly wmsPickingRoute where wmsPickingRoute.RecId==5637144577;//iisi sendiri jngn malas
    
    srsTmpDataStore.Value = Global::buf2Con(wmsPickingRoute);
    ttsbegin;
    srsTmpDataStore.insert();
    ttscommit;
 
    aicontroller.parmReportName(ssrsReportStr(WmsPickingList_OrderPick,Report));
    aicontroller.parmShowDialog(false);
 
    aiController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Screen);
   // aiController.parmReportContract().parmPrintSettings().printerName(“Xerox WorkCentre 3210 PCL 6 (Copy 1)”);
 
    aiContract.parmPickingRouteId(srsTmpDataStore.recid);
    aiContract.parmDocumentTitle(“x”);
    aiContract.parmShowRegistered(true);
    aiContract.parmShowActivated(true);
    aiContract.parmShowStarted(true);
    aiContract.parmShowPicked(true);
    aiContract.parmShowStaged(true);
    aiContract.parmShowLoaded(true);
    aiContract.parmShowCancelled(false);
    aiContract.parmPrintCopyOriginal(PrintCopyOriginal::Original);
 
    aiController.parmReportContract().parmRdpContract(aiContract);
    //aicontroller.startOperation();
 
    //aiController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
 
    // Run the report
    aiController.runReport();
}

get WorkFlow Approval Name

WHILE select workflowtrackingstatustable
join workflowtrackingtable
where workflowtrackingstatustable.ContextRecId == PurchTable.RecId //RecId of the record
&& workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem
&& workflowtrackingtable.TrackingType == workflowtrackingtype::Approval
&& workflowtrackingtable.WorkflowTrackingStatusTable == workflowtrackingstatustable.RecId
{
     info(strFmt(“%1″,SysWorkflowHelper::getDirPartyNameFromUserId(workflowtrackingtable.USER)));
}

or

display HcmWorkerName displayWorkflowApproverName()
{
    WorkflowTrackingTable tracking;
    WorkflowTrackingStatusTable trackingStatus;
    WorkflowWorkItemTable workitem;
    HcmWorkerName ret = "";
    UserInfo user;

    select tracking order by tracking.createdDateTime desc join trackingStatus
        where tracking.WorkflowTrackingStatusTable == trackingStatus.RecId
        && tracking.TrackingType != WorkflowTrackingType::Completion
        && ((tracking.TrackingContext == WorkflowTrackingContext::Step) || (tracking.TrackingContext == WorkflowTrackingContext::Task))
        && trackingStatus.ContextTableId==this.TableId && trackingStatus.ContextRecId == this.RecId;
    select workitem where workitem.RefRecId == this.RecId && workitem.RefTableId == this.TableId &&
        ((workitem.Status == WorkflowWorkItemStatus::Pending) || (workitem.Status == WorkflowWorkItemStatus::Delegated));

    return HcmWorker::find(HcmWorker::userId2Worker(workitem.UserId)).name();


}

fix bugs Remove Sales Line when the sales Line already pick,pack,or invoiced on AX2012

i don’t know this is a bug come from our own customize or bugs originated from AX 2012.
anyway we have to fix this. Our client found this bug and requesting to add some validation and disable Remove Button on sales line when already pick.

so how i did this :

go to form SalesTable,
locate button Remove , and set AutoDeclaration to Yes, so we can call this button and disable or enable it via code.
look for method “active” in datasource SalesLine.

add this code below :

//AIFD fix bug remove button
    InventTrans     inventTransLoc;
    boolean         cekStatus;
    WMSOrderTrans   wmsOrderTrans;
  //END


    //add this code before return ret;
    cekStatus = true;
    //cek status dari inventtrans
    while select inventTransLoc   where inventTransLoc.InventTransOrigin==
    InventTransOrigin::findByInventTransId(SalesLine.InventTransId).RecId
    {
        if(inventTransLoc.StatusIssue != StatusIssue::OnOrder)
        {
            cekStatus = false;
            break;
        }
    }

    //cek status dari picking list
    while select wmsOrderTrans where   wmsOrderTrans.inventTransId==SalesLine.InventTransId
    {
        cekStatus = false;
        break;
    }


    if( salesLine.SalesStatus == SalesStatus::Backorder &amp;&amp; cekStatus)
    {
        LineStripDelete.enabled(true);
    }
    else
    {
       LineStripDelete.enabled(false);
    }
    
    //END

voila… happy Daxing !!

add Department Name to grid form PurchReqTableListPage

On table purchReqTable,

create new method and add this

display public server Name aiDepartment()
{
    return HcmWorker::find(this.Originator).primaryDepartmentName();
}

on form PurchReqTableListPage, right click and choose Restore (to restore DataSource).
and add string to Grid, set datasource and method on properties.

voila !! done..

happy Daxing… !!

Create Number Sequence on Sales Module, custInvoiceJour

read more on
http://swathidynamicsax.blogspot.com/2012/07/simple-steps-to-create-number-sequence.html

My case is to create number sequence on Sales Module,
so i had to modify some code on there..

on table SalesParameters.

static client server NumberSequenceReference AI_numRefPackingListId()
{
    return NumberSeqReference::findReference(extendedTypeNum(AI_PackingListId));
}

add this code to class NumSeqModuleSalesOrder\LoadModule

//AIFD_ seq packingListId
datatype.parmDatatypeId(extendedTypeNum(AI_packingListId));
datatype.parmReferenceHelp(literalStr("Packing List Id setiap create Invoice"));
datatype.parmReferenceLabel(literalStr("Packing List Id"));
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.parmSortField(66);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
//END

and modify the code on job

static void AIFD_JobSequence(Args _args)
{
   NumberSeqModuleSalesOrder NumberSeqModuleSalesOrderLoc = new NumberSeqModuleSalesOrder();
   NumberSeqModuleSalesOrderLoc.load();
}

then run wizard number sequence and run this job

static void AIFD_TestRunSeqNum(Args _args)
{
   NumberSeq numberSeq;
   AI_PackingListId num;
   ;
   numberSeq = NumberSeq::newGetNum(SalesParameters::AI_numRefPackingListId());
   num = numberSeq.num();
   info(num);
}

done.. voila, i need to add my newly added number sequence to my customize CustInvoiceJour,
so when sales Invoice is created, my newly added number sequence is generated and automatically save in table CustInvoiceJour..

how i did this :

1. add new field on custInvoiceJour, i named it AI_PackingListId and set the extended data type to my new data type.

2. modify some code on class SalesInvoiceJournalCreateBase\initJournalHeader

NumberSeq numberSeqLoc;
AI_PackingListId numPackingListId;

numberSeqLoc = NumberSeq::newGetNum(SalesParameters::AI_numRefPackingListId());
numPackingListId = numberSeqLoc.num();

//add this code below custInvoiceJour.initFromSalesParmTable(salesParmTable);
custInvoiceJour.AI_PackingListId = numPackingListId;
//END

3. Last, Generate Incremental CIL , dont forget that 🙂
Voila.. done !!

happy Daxing !!

Send Email Proforma Sales Customize with Job.

class : SalesInvoiceController.OutputReport ()

//AIFD custom send email proforma testing
SrsReportEMailDataContract emailContract;
SRSPrintDestinationSettings         printSettings;
//END

//just example.. you can customize the parameter field Subject etc on email with your own parameter and conditions.
//add this code below at the bottom of class OutputReport
if(custInvoiceJour.isProforma())
{
    emailContract = new SrsReportEMailDataContract();
 
    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);
    emailContract.parmSubject(“My Report”);
    emailContract.parmTo(“jimmi.tandiah@yahoo.com”);
 
    printSettings = this.parmReportContract().parmPrintSettings();
 
    printSettings.printMediumType(SRSPrintMediumType::Email);
    printSettings.parmEMailContract(emailContract);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
 
    formLetterReport.getCurrentPrintSetting().parmPrintJobSettings(printSettings);
}

—————————-
Job example

static void AI_TestEmailProforma(Args _args)
{
    SalesFormLetter letter = SalesFormLetter::construct(DocumentStatus::Invoice);
    SalesTable sale = SalesTable::find(‘SO-14000599′);

    ttsBegin;
    letter.update(sale, systemDateGet(), SalesUpdate::All, AccountOrder::None, true, true,true);
    ttsCommit;
}

Refreshing Master Form Data Source from Child Form

//Example when modifying checkbox value and modify parent datasource,
// it will have an error unless if you refreshing parent datasource after you modify it,

public boolean modified()
{
//AIFD_ custom exchrate custtrans -> ledgerjournal trans
#Task
LedgerJournalTrans ledgerJournalTransLoc;
FormDataSource fds;

//END

boolean ret;

ret = super();

//AIFD_ custom exchrate custtrans -> ledgerjournal trans
ttsBegin;
if(this.checked())
{
select forUpdate LedgerJournalTransLoc where ledgerJournalTransLoc.RecId == originator.RecId;
LedgerJournalTransLoc.ExchRate = CustTrans.ExchRate;
ledgerJournalTransLoc.update();
}
else
{
select forUpdate LedgerJournalTransLoc where ledgerJournalTransLoc.RecId == originator.RecId;
LedgerJournalTransLoc.ExchRate = 100;
ledgerJournalTransLoc.update();

}

ttsCommit;

fds = element.args().record().dataSource();
fds.research(true);

fds.refresh();
//END

 

return ret;
}

Weight Detection PortComm

//Get PortComm number that already set from .txt file on local drive.
private str getPortComm()
{
    #file
    str getCOMport;
    boolean cekPortExist;
    AsciiIo file;
    Container data;
    int i;
    System.IO.FileInfo fileInfo;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();
    fileInfo = new System.IO.FileInfo(@”C:\portcomm.txt”);
    if(fileInfo.get_Exists())
    {
        file = new AsciiIo(@”C:\portcomm.txt”,#io_read);
        file.inFieldDelimiter(‘\t’);
        file.inRecordDelimiter(‘\n’);

        if(file)
        {
            while(file.status() == IO_Status::Ok)
            {  
                data = file.read();
                for(i = 1; i <= conlen(data); i++)
                {
                    getCOMport = any2str(conpeek(data, i));
                }
            }
        }

    }

    return strLTrim(getCOMport);
}

————————————

//Get Weight from PortComm
private real AI_getWeight()
{
    System.String netstring;
    System.String sample;

    int WeightInReal;
    int tryCount;
    str value;
    str value2;
    str portComm;
    System.IO.Ports.SerialPort port3;
    real weightFinal;

    tryCount = 0;

    portComm = this.getPortComm();
    if(portComm)
    {
        port3 = new System.IO.Ports.SerialPort();
        value = “0”;
        port3.set_PortName(portComm);
        port3.set_BaudRate(9600);
        port3.set_Parity(System.IO.Ports.Parity::None);
        port3.set_DataBits(8);
        port3.set_StopBits(System.IO.Ports.StopBits::One);
        port3.set_Handshake(System.IO.Ports.Handshake::None);

        try
        {
            port3.Open();
            while(tryCount<1)
            {
                WeightInReal = sleep(500);
                netstring = port3.ReadExisting();
                value = netstring;
                value2 = value;
                tryCount++;
            }
            port3.Close();
            port3.Dispose();
        }
        catch(Exception::CLRError)
        {
            info(“Wrong Port Comm Number”);
        }

        value2 = strReplace(value,”=”,””);
        value2 = strReplace(value2,”-“,””);
        value2 = strLTrim(value2);
        value2 = subStr(value2,1,6);
        weightFinal = str2num(value2);
    }
    else
    {
        info(“Check file portcomm.txt at C:\””);
    }

    if(!weightFinal)
    {
        info(“Please check your device, clarify it already turned on”);
    }
    return weightFinal;
}

—————————

on method button clicked, override.. some example here for you

void clicked()
{
    real _value;
    InventTable inventTableLoc;
    super();
    _value = this.AI_getWeight();
    
    Select * from inventTableLoc where inventTableLoc.ItemId == ProdJournalProd.ItemId;
    if(_value)
    {
        if(inventTableLoc.AISatuanPrimer!=”Kg”)
        {
            ProdJournalProd.AISatuanTertier = _value;
            ProdJournalProd_AISatuanTertier.enabled(False);
        }
        else
        {
            ProdJournalProd.AISatuanTertier =_value;
            ProdJournalProd_AISatuanTertier.enabled(True);
        }
    }
    ProdJournalProd_ds.executeQuery();
}

Location and Pallet Id Validation before posting form: ProdJournalTransBOM

void clicked()
{
    WMSPallet wmsPallet;

    select wmsPallet where wmsPallet.wMSPalletId==InventDimGrid_wMSPalletId.valueStr();
    if(wmsPallet.wMSLocationId != InventDimGrid_wMSLocationId.valueStr())
    {
        warning(strFmt(“Number of pallet %1 does not match in number of location %2″,InventDimGrid_wMSPalletId.valueStr(),InventDimGrid_wMSLocationId.valueStr()));
        error(“Posting has been canceled”);
    }
    else
    {
        super();
    }
}

Multi Print Report based on Selected Items on Grid

void clicked()
{
    //AIFD_PrintBarcode
    AI_PrintBarcodeController aiBarcode = new AI_PrintBarcodeController();
    AI_PrintBarcodeContract aiContract = new AI_PrintBarcodeContract();
    ProdJournalProd prodJournalProdLoc;

    super();

    prodJournalProdLoc = ProdJournalProd_ds.getFirst(true);

    while (prodJournalProdLoc)
    {
        aiBarcode.parmReportName(ssrsReportStr(AI_PrintBarcoderReport,Report));
        aiBarcode.parmShowDialog(false);
        aiContract.parmRecordId(prodJournalProdLoc.RecId);
        aiContract.parmDocumentTitle(“x”);
        aiBarcode.parmReportContract().parmRdpContract(aiContract);
        aiBarcode.startOperation();

        prodJournalProdLoc = ProdJournalProd_ds.getNext();
    }
    //END
}

Update Serial Inventory via SQL

select * from ECORESTRACKINGDIMENSIONGROUP

select * from ECORESTRACKINGDIMENSIONGROUPITEM where itemid = '000057610'
select * from ECORESTRACKINGDIMENSIONGROUPPRODUCT where PRODUCT = '5637294284'

select * from ECORESTRACKINGDIMENSIONGROUPFLDSETUP

update ECORESTRACKINGDIMENSIONGROUPITEM set TRACKINGDIMENSIONGROUP='5637144577' where itemid='000057610'
update ECORESTRACKINGDIMENSIONGROUPPRODUCT set TRACKINGDIMENSIONGROUP='5637144577' where product='5637294284'

Print SSRS Barcode in AX 2012

Hello there,
just working on project that need to print somekind of barcode label for Production’s Serial Number.

you need to convert your string to Barcode string :

__________________________________________________________

public BarCodeString ShowBarcode(str _text)
{
  Barcode barcode;

  barcode = Barcode::construct(BarcodeType::Code128);
  barcode.string(true, _text);
  barcode.encode();

  return barcode.barcodeStr();
}

_________________________________________________________

then do this on Visual Studio 😀

Untitled

 

result :

Untitled

Happy DAXing !!