2012年11月8日星期四

How to using code changed font in AX2012

AX2012 have no setup the font on user options.
So, I write a job update the userId [admin]'s font

static void THK_7519_ChangeUserFont(Args _args)
{
    UserInfo    UserInfo;
    container   con;// #! INCIDENT !#.LAST.07.11.12.JXie7519:
;
    ttsBegin;
    select firstonly forupdate UserInfo
        where UserInfo.id == "admin";

    if(UserInfo)
    {
        UserInfo.propertyFontName   = "Tahoma";
        UserInfo.formFontName       = "Tahoma";
        UserInfo.reportFontName     = "Tahoma";

        UserInfo.doUpdate();

        con = [ "Property : "   + UserInfo.propertyFontName, UserInfo.propertyFontSize,
                "Form : "       + UserInfo.formFontName, UserInfo.formFontSize,
                "Report : "     + UserInfo.reportFontName, UserInfo.reportFontSize];
        info(con2Str(con));
    }
    ttsCommit;
}

How to using code changed comment in AX2012



EditorScripts\LAST_comment


void LAST_comment(Editor editor)
{
    xppSource xppSource = new xppSource(editor.columnNo());
    Source template = xppSource.comment();
    ;
    editor.insertLines(template);
}


xppSource\comment
// VAR Changed on 08 Nov 2012 at 13:55:27 by JXie7519
Source comment()
{
    UserInfo    UserInfo;
    Name        name;
;
    /* Original
    source += strfmt("// #! INCIDENT !#.LAST.%1.%2:", date2str(systemdateget(), 123,2,2,2,2,2, DateFlags::None), curuserId());
    */

    // VAR Changed on 08 Nov 2012 at 13:55:27 by JXie7519 - start
    select firstOnly UserInfo where UserInfo.id == curUserId();

    name = subStr(UserInfo.networkAlias, strLen(UserInfo.networkAlias) - 3, strlen(UserInfo.networkAlias));
    name = Global::isInteger(name) ? name : UserInfo.id;
    
    source += "// " + strUpr(enum2str(currentAOLayer())) + " Changed on " + date2str(today(),321,2,3,2,3,4, DateFlags::FormatAll ) + " at " + time2str(timenow(), 1, 1) + " by " + name + " - start" + '\n' +
       "\t" + "// " + strUpr(enum2str(currentAOLayer())) + " Changed on " + date2str(today(),321,2,3,2,3,4, DateFlags::FormatAll ) + " at " + time2str(timenow(), 1, 1) + " by " + name + " - end" + '\n';
    // VAR Changed on 08 Nov 2012 at 13:55:27 by JXie7519 - end

    return source;
}


2012年11月5日星期一

How to using code find record by RecId

One method

1-1) using common by tableId and recId
public Common findRecord(TableId _tableId, RecId _recId, Boolean _forUpdate = false)
{
    Common      common;
    DictTable   dictTable;
    ;
    dictTable = new DictTable(_tableId);
    common = dictTable.makeRecord();
  
    common.selectForUpdate(_forUpdate);
  
    select common
    where common.RecId == _recId;
  
    return common;
}

1-2) using query

Query                q = new Query;
QueryBuildDatasource qbds;
QueryRun             qr;
;
qbds = q.addDataSouce(tableid);
qbds.addRange(tableid2name(tableid), RecId)).value(queryValue
(yourrecid));

qr = new QueryRun(q);

if (queryRun.next())
{
    common = qr.get(tableid);
}

1-3)using loop Dictionary

    Dictionary      dictionary;
    TableId         tableId;  
    tableName       tableName;  
    common c;
    DictTable   dt;
    ;  
  
    dictionary = new Dictionary();  
  
    tableId = dictionary.tableNext(0);  
    tableName = dictionary.tableName(tableId);  
  
    while (tableId)  
    {  
        //info(strfmt("%1 - %2",int2str(tableId), tableName));
  
        tableId = dictionary.tableNext(tableId);  
        tableName = dictionary.tableName(tableId); 

        dt = new DictTable(tableId);
        c=dt.makeRecord();
        select c where c.RecId==53883;
        if(c)
        {
            info(strfmt("%1 - %2",int2str(tableId), tableName));
            break;
        }
         
    }


Two method

    SQLDictionary   dictTable;
    common          c;
    DictTable       dt;
    ;
  
    while select * from dictTable where dictTable.fieldId == 0
    {
        //info(strfmt("%1 - %2", dicttable.name ,dicttable.tabId));

        dt = new DictTable(dictTable.tabId);
        c=dt.makeRecord();
        select c where c.RecId==53883;
        if(c)
        {
            info(strfmt("%1 - %2", dicttable.name ,dicttable.tabId));

            break;
        }

    }


/*  incompleted
    UtilIdElements  uie;
    common          c;
    DictTable       dt;
    ;

    while select uie where uie.recordType==utilelementtype::Table
   //&& uie.utilLevel==UtilEntryLevel::usr
    {
        info(strfmt("%1 --- %2",uie.name , uie.id));

        dt = new DictTable(uie.id);
        c=dt.makeRecord();
        select c where c.RecId==53883;
        if(c)
        {
            print uie.name;
            break;
        }

    }
*/

How to using code recalculation Inventsum with Item number

Question?

I have a big problem ... I have a diference between inventtrans and inventsum for some items ...
I want to say that the qty in invetsum is not equal to the sum of qty in Inventrans.What can i do to solve this problem without trying to have a job to correct that.
reply as below :

1)The tools to Check and Fix the problem are in Basic/Periodic/Consistency check.

2)with the class InventSumRecalcItem you can do a recalculation of the inventsum based on the inventtrans data.But befor you run this, please take a backup of db.
Sample script to recalc the inventsum.
Hope this helps you.
--------------------------------------------------------------------
You can rebuild InventSum.Very simple example for a particular ItemId in InventTable:

void clicked() //from button in InventTable Form
{
    InventSumReCalcItem inventSumReCalcItem;
;
    super();
    ttsbegin;

    inventSumReCalcItem = new InventSumReCalcItem(inventTable.ItemId,                  true,CheckFix::Fix);

    inventSumReCalcItem.updateNow();
}

2012年10月29日星期一

How to using code create purchase order


Purchase Order using X++
In this post we will learn the below using X++ :
 1) How to Create Purchase Order
 2) How to Create Purchase Order Line
 3) How to Post Purchase Order

static void THK_createPurchaseOrder(Args _args)
{
    PurchTable      purchTable;
    PurchLine       pline;
    NumberSeq       ns;
    PurchID         pid;
    PurchFormLetter pl;
;
    //Create Purchase Order
    ns                      = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().NumberSequence);
    purchTable.initValue();
    pid                     = ns.num();
    purchTable.PurchId      = pid;
    purchTable.OrderAccount = "4202";
    purchTable.initFromVendTable();
    purchTable.insert();

    //Create Purchase Line
    pline.clear();
    pline.PurchId   = pid;
    pline.ItemId    = "1109";
    pline.createLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);
    info("Purchase Order Created Sucessfully");

    //Post the PO
    pl = PurchFormLetter::construct(DocumentStatus::Invoice);
    pl.update(PurchTable::find(pid), pid, SystemDateGet(),PurchUpdate::All,AccountOrder::None,false,true);
    info("Posted Sucessfully");
}

How to using code create and post inventory jounral


Create & Post Inventory Journal in AX 2009
Following is job which will create and post the Inventory Journal in ax 2009

static void THK_createMovJournal(Args _args)
{
    InventJournalTable      journalTable;
    InventJournalTrans      journalTrans;
    InventJournalTableData  journalTableData;
    InventJournalTransData  journalTransData;
    InventTable             inventTable;
    inventDim               tmpinventDim;
    Counter                 cnt;
    InventJournalCheckPost  journalCheckPost = new InventJournalCheckPost();
    DialogButton            dbtn;
;
    journalTableData = JournalTableData::newTable(journalTable);
    journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);

    // create JournalTable

    journalTable.clear();

    journalTable.JournalId      = journalTableData.nextJournalId();
    journalTable.JournalType    = InventJournalType::Movement;
    journalTable.JournalNameId  = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);

    journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));

    // create JournalTrans
    select firstonly inventTable;
    for(cnt=1;cnt<10;cnt++)
    {
        journalTrans.clear();
        journalTransData.initFromJournalTable();

        journalTrans.TransDate              = systemdateget() + 1 div 2;
        journalTrans.ItemId                 = '1103';    //inventTable.ItemId;
        journalTrans.Qty                    = 100;
        journalTrans.CostAmount             = 100;
        journalTrans.LedgerAccountIdOffset  = '110170';

        // Dimension details

        tmpinventDim.InventLocationId  = '11';
        journalTrans.InventDimId    ='00000061_069'; //InventDim::findOrCreate(inventDim).inventDimId;

        journalTransData.create();
    }

    journalTable.insert();

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

    if(box::yesNo("Do you want to Post Now?",DialogButton::No)==DialogButton::Yes)
    {
        InventJournalCheckPost::newPostJournal(journalTable).run();
    }
    else
    {
        box::info("Not Posted");
    }
    info("done");
}

How to using code create sales order


/*sales Order using X++
Hi,In this post we will learn the below using X++ :
 1) How to Create Sales Order
 2) How to Create Sales Order Line
 3) How to Post Sales Order
*/
public static void THK_createSalesOrderDemo(Args _s)
{
// Create the Sales Order
    SalesTable      salesTable;
    SalesLine       sl;
    
    SalesId         sid;
    NumberSeq       NumberSeq;
    SalesFormLetter fl;
;
    NumberSeq           = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
    sid                 = NumberSeq.num();
    
    //create sales order header
    salesTable.SalesId  = sid;
    salesTable.initValue();
    salesTable.CustAccount = "1101";
    salesTable.initFromCustTable();
    salesTable.insert();

    //Create the Sales Line with the created Sales Order
    sl.SalesId = sid;
    sl.ItemId  = "1109";
    sl.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);

    info("Sales Order Created with Line");

    //How to Post the Sales Order Invoice
    fl=SalesFormLetter::construct(DocumentStatus::Invoice);
    fl.update(SalesTable::find(sid));
    info("Sales Order Posted");
}