Wednesday, August 9, 2017

Create Number Sequence on AX 2012 R3

public static void Create(
NumberSequenceCode  _numSeqCode,
Name    _txt,
NumberSequenceRange _highest,
NumberSequenceRange _lowest,
NumberSequenceRange _nextRec,
Name    _prefix,
Name    _format,
str 1 _manual,
str 1 _cont,
Name    _numSeqScopeStr
)
{
    NumberSequenceTable numberSeqTable;
    NumberSequenceScope numberSeqScope;
    NumberSequenceReference numberSeqRef;
    RefRecId _numSeqScopeR,_numSeqIdR;
    container   segments, segmentReset;
    str annotatedFormat, format;
    ;
    _nextRec =1;
    select firstonly * from numberSeqScope where numberSeqScope.DataArea == _numSeqScopeStr;
    _numSeqScopeR = numberSeqScope.RecId;

    if(!NumberSequenceTable::findByNaturalKey(_numSeqCode,_numSeqScopeR))
    {
        ttsBegin;
        numberSeqTable.clear();
        numberSeqTable.NumberSequence   = _numSeqCode;
        numberSeqTable.Txt              = _txt;
        numberSeqTable.Highest          = _highest;
        numberSeqTable.Lowest           = _lowest;
        numberSeqTable.NextRec          = _nextRec;

        if(_manual == 'Y')
        { numberSeqTable.Manual           =  NoYes::Yes; }

        if(_cont == 'Y')
        { numberSeqTable.Continuous       =  NoYes::Yes; }

        segments = segmentReset;
        //segments += [[-1, conPeek(rec, 8)]];// 0 company, -1 constant, -2 alphanumeric
        if(_prefix)
        { segments += [[-1, _prefix]]; }
        segments += [[-2, _format]];

        annotatedFormat  = NumberSeq::createAnnotatedFormatFromSegments(segments);
        format           = NumberSeq::createAnnotatedFormatFromSegments(segments, false);
        numberSeqTable.AnnotatedFormat      = annotatedFormat;
        numberSeqTable.Format               = format;
        numberSeqTable.NumberSequenceScope  = _numSeqScopeR;
        numberSeqTable.validateWrite();
        numberSeqTable.insert();
        ttsCommit;
    }
}

Friday, June 30, 2017

Open Source and Freeware Tools for Productivity

File Editor

Notepad Plus Plus
notepad-plus-plus.org

File and Folder Comparison
 
Winmerge
winmerge.org


Image Editor

Paint .Net
www.getpaint.net

Icon Editor 

Green Fish Icon Editor
greenfishsoftware.blogspot.co.id


Color Finder

Hex Color Finder
www.hexcolorfinder.com

Multimedia Converter

Format Factory
www.pcfreetime.com/formatfactory

PDF Creator

doPDF
www.dopdf.com

DVD Burner

InfraRecorder
infrarecorder.org

Archiver

Peazip
peazip.org

Sunday, March 12, 2017

Computed column date to get max day on month for AX 2012 R3

public static server str getMaxDateTransDate()
{
    #define.ViewName(InventValueTransViewSumLoc)
    #define.DataSourceName("InventValueTransView")
    #define.FieldDisplayValue("RecID")

    str sWhereClause1;
    DictView dictView;
    SysDictTable dicTable;

    // Construct a DictView object for the present view.
    dictView = new DictView(tableNum(#ViewName));
    //Construct a table object for the account table
    dicTable = new SysDictTable(tableNum(InventValueTransView));

    // Create the where clause
    sWhereClause1 = DictView.computedColumnString
    (
        'InventValueTransView',
        fieldStr(InventValueTransView, RecId),
        FieldNameGenerationMode::WhereClause
    );

    return strFmt
    (
        //'select year(TransDate) from %1 where %2 = %3',
        'SELECT DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,TRANSDATE)+1,0))',
        dicTable.name(DbBackend::Sql),
        dicTable.fieldName(fieldNum(InventValueTransView, RecId), DbBackend::Sql),
        sWhereClause1
    );
}

Thursday, February 23, 2017

Rebuild Management Report 2012 Datamart for AX 2012 R3

DELETE
=======
1. Backup datamart database. i.e.: ManagementReporterDM
2. Run MR Config Console
3. Select database connection on ERP Integration
4. Disable Integration
5. Remove
6. Stop both MR Services
7. Delete Database : ManagementReporterDM

RECREATE
=========
8. Run both MR Services
9. Configure datamart

Thursday, October 20, 2016

Run report SSRS SrsReportRunController and passing parameter from form in AX 2012 R3


void clicked()
{
    Query query;
    LedgerJournalTable          dataTable;
    SrsReportRunController      controller;
    ;

    dataTable = LedgerJournalTable;

    //info(strFmt('%1',dataTable.JournalNum));

    controller = new SrsReportRunController();
      controller.parmReportName('MyCustomReport.PrecisionDesign1');

    query = controller.parmReportContract().parmQueryContracts().lookup('
MyCustomReport_DynamicParameter');
    //Set parameter value;
    query.dataSourceNo(1).clearRanges();  
    query.dataSourceNo(1).addRange(fieldNum(
MyCustomReportView, JournalNum)).Value(dataTable.JournalNum);

    controller.runReport();

}

 


Reference:
http://xhellot.blogspot.co.id/

Thursday, October 13, 2016

Reverse Settlement Accout Receivable on AX 2012 R3

static void Update_Reverse_Settlement(Args _args)
{
    CustTrans           invCustTrans,findCustTrans;
    SpecTransManager    specTransManager;
    DocumentNum         invdocnumx,paydocnumx;
    CustSettlement      custSettlement;
    AccountNum          accnumx;
    date                paydatex;
    CustTable           custTable;
    ;

    invdocnumx  = 'PY16100100561';
    accnumx     = '631331';

    select invCustTrans
    order by TransDate asc
    where   invCustTrans.DocumentNum == invdocnumx
        &&  invCustTrans.AmountMST > 0
        &&  invCustTrans.AccountNum == accnumx;
   
    while select findCustTrans where findCustTrans.RecId == invCustTrans.RecId
    {       
        custTable = custTable::find(findCustTrans.AccountNum);

        if(findCustTrans.TransType != ledgerTransType::Payment)
        {
            //We must go to the customer settlement table and locate the records that were used to settle the invoice in scope and pass them into the class
            // that manages the marking and updating of applied credits and payments to invoices. We remove the credit marking to remove the link between the invoice
            //and the credits used to settle the invoice. Then we must reverse the transactions using the reverseTransact method on the customer transaction table
              select firstonly custSettlement where custSettlement.TransCompany == findCustTrans.dataAreaId &&
                                                    custSettlement.TransRecId   == findCustTrans.RecId &&
                                                    custSettlement.AccountNum   == findCustTrans.AccountNum;

            specTransManager = SpecTransManager::newRefTableId(custTable,tablenum(custSettlement), true);
            specTransManager.insert(custSettlement.DataAreaId, custSettlement.TableId, custSettlement.RecId, custSettlement.SettleAmountCur, findCustTrans.CurrencyCode);
            custSettlement.CustVendSettlement::markOffsets(specTransManager, findCustTrans.CurrencyCode, true);

            if (CustTrans::reverseTransact(custTable,null,settleDatePrinc::DateOfPayment,custSettlement.TransDate))
            {
                specTransManager.deleteAll();
            }
        }
    }
    info(strFmt('Done %1',findCustTrans.txt));


}

Reference:

http://www.winfosoft.com/blog/uncategorized/dynamics-ax-how-to-void-an-ar-payment-and-remove-applied-credits-to-invoices-using-code
 

Monday, October 10, 2016

Using jumpref method on PurchReqLine on AX 2012 R3

Override method jumpRef ItemId field on Form DataSources

public void jumpRef()
{
    //super();
    PurchReqLine    _purchRLine;
    Args            args;
    MenuFunction    menuFunction;
    Common          rec;
    ;   
    _purchRLine = PurchReqLine;
   
    rec = InventTable::find(_purchRline.ItemId);

    args = new Args();
    args.caller(element);
    args.lookupRecord();
   
    args.record(rec);
    args.caller(element);

    // Create a new MenuFunction that launches the Reasons Menu Item

    menuFunction = new MenuFunction(menuitemdisplaystr(EcoResProductDetailsExtended),MenuItemType::Display);

    menuFunction.run(args);       
}