Popular Posts

Monday 26 September 2011

Transfer Journals

Transfer Journals
Transfer the journals from one warehouse to another warehouse.


static void CreateTransferJournal(Args _args)
{
    InventJournalTable      inventJournalTable;
    InventJournalTrans      inventJournalTrans;
    InventJournalCheckPost  inventJournalCheckPost;
    NumberSeq               num;
    boolean                 _throwserror=true;
    boolean                 _showinforesult=true;
    InventDim               frominventDim,ToinventDim;
    ;
    ttsbegin;

    inventJournalTable.clear();
    num                                 =   new NumberSeq();
    num                                 =   NumberSeq::newGetNum(InventParameters::numRefTransferId());
    inventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().TransferJournalNameId));
    inventJournalTable.Description      =   "Inventory Transfer Journal";
    inventJournalTable.SystemBlocked    =   true;
    inventJournalTable.insert();
    info("Entry Inserted");
    info(strfmt("The Voucher generated is %1",inventJournalTable.JournalId));

    inventJournalTrans.clear();
    inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    inventJournalTrans.ItemId            =   "1101";
    frominventDim.InventLocationId="21";
    //frominventDim.configId        = "02";
    frominventDim.inventSiteId    ="2";
    ToinventDim.InventLocationId = "34";
    ToinventDim.InventSiteId     = "3";
   // ToinventDim.configId        =  "02";
    ToinventDim                 =  InventDim::findOrCreate(ToinventDim);


    frominventDim = InventDim::findOrCreate(frominventDim);
    inventJournalTrans.InventDimId  =   frominventDim.inventDimId;
    inventJournalTrans.initFromInventTable(InventTable::find("1101"));
    inventJournalTrans.Qty               =   10;
    inventJournalTrans.ToInventDimId     =   ToinventDim.inventDimId;
    inventJournalTrans.TransDate         =   SystemDateget();
    inventJournalTrans.insert();

    inventJournalCheckPost               =  InventJournalCheckPost::newJournalCheckPost(JournalCheckpostType::Post,inventJournalTable);
    inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
    inventJournalCheckPost.parmShowInfoResult(_showinforesult);
    inventJournalCheckPost.run();

    inventJournalTable.SystemBlocked    =   false;
    inventJournalTable.update();

    ttscommit;
    }

Journals posting

Posting Journals
static void Journal_Kis(Args _args)
{
    InventJournalTable      journalTable;
    InventJournalTrans      journalTrans;
    InventJournalTableData  journalTableData;
    InventJournalTransData  journalTransData;
    InventTable             inventTable;
    InventDim               inventDim;
    Counter                 cnt;
    InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
    ;

    journalTableData = JournalTableData::newTable(journalTable);
    journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
    // Init JournalTable

    journalTable.clear();

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

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

    // Init JournalTrans
    select firstonly inventTable where inventTable.ItemId == 'item12';
//   for(cnt=1;cnt<10;cnt++)
//   {
        journalTrans.clear();
        journalTransData.initFromJournalTable();

        journalTrans.TransDate = systemdateget() + 1 div 2;
        journalTrans.ItemId = inventTable.ItemId;
        journalTrans.Qty = 100;

        journalTrans.CostAmount = 100;

        // Dimension details

        inventDim.InventLocationId = '11';
        inventDim.InventSiteId   = '1';
        journalTrans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

        journalTransData.create();

  //  }

    journalTable.insert();

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

}

Monday 22 August 2011

Port Numbers in ax

AOS port numbers are essentially TCP/IP port numbers.  TCP/IP port numbers have a range from 1024 to 49151.  So in theory, you should be able to use port numbers from this range.

Another type of Ax Application Backup


There is no auto backup of application option in Dynamics AX.
In the past, I used DOS command script to do the following in the mid night when it was acceptable for AOS to be unavailable -
1) Stop the AOS
2) Delete .aoi file
3) Used Robocopy script to backup the application layer.
4) Restart AOS.
The beauty with Robocopy is - it is intelligent enough so that only those files which had its timestamp changed would be backed up.

Upgrading Ax4.0 to Ax2009 Bom error

I upgrade ax 4.0 to ax 2009.I saw item master ItemType field shows only Item,Service.But i saw in base enums itemType shows Item,Bom,Service.what should i do visible BOM on itemType lookup in item master?
Soloved This Problem
Manufacturing is a generic term for all production elements. Actually having opened it the BOM configuration is under logistics. If this is selected you should be able to see the BOM option on the item master and in inventory management. If it is selected and you still cannot see it you would need to trouble shoot the upgrade procedure as this is where the issue will lie.

Sending Mail Through X++

static void Email(Args _args)
{
    CustTable                   custTable;
    System.Text.StringBuilder   htmlTable;
    SysMailer                   mailer;
    ;

    htmlTable   = new System.Text.StringBuilder();
    htmlTable.Append(@"<Caption>Blue Company Customers");
    htmlTable.Append(@"</Caption></br>");
    htmlTable.Append("<TableBorder = 1>");
   
    while select custTable where custTable.CustGroup == '10'
    {
        htmlTable.Append("<TR ALIGN='CENTER'>");
        htmlTable.Append("<TD>");
        htmlTable.Append(custTable.AccountNum);
        htmlTable.Append("</TD>");
        htmlTable.Append("<TD>");
        htmlTable.Append(custTable.NameAlias);
        htmlTable.Append("</TD>");
        htmlTable.Append("</TR>");
    }
   
    htmlTable.Append("</TABLE>");

    mailer  = new SysMailer();
    mailer.htmlBody(htmlTable.ToString());
    mailer.subject("Automated Mail - Customers");
    mailer.fromAddress("kishorem@b2bsoftech.local");
    mailer.tos().appendAddress("chakradhar@b2bsoftech.local");
    mailer.SMTPRelayServer("192.168.4.67",87,"AXMail","1234",false);
    mailer.sendMail();
}

Wednesday 3 August 2011

Excel creation through x++ 1

static void nestingExcel(Args _args)
{
    SysExcelStyles          styles;
    SysExcelStyle           style;
    SysExcelFont            font;
    #AviFiles
    SysOperationProgress    progress = new SysOperationProgress();
    SysExcelApplication     sysExcelApplication;
    SysExcelWorkbooks       sysExcelWorkBooks;
    SysExcelWorkbook        sysExcelWorkBook;
    SysExcelWorkSheets      sysExcelWorkSheets;
    SysExcelWorkSheet       sysExcelWorkSheet;
    TvItemscrTable          scrTable;
    TvItemScrapLInes        scrLines;
    TvProdProfiles          prodProfiles;
    int                     j,k;
    int                     len[];
    ;
    sysExcelApplication     = SysExcelApplication::construct();
    sysExcelWorkBooks       = sysExcelApplication.workbooks();
    sysExcelWorkBook        = sysExcelWorkBooks.add();
    styles                  = sysExcelWorkBook.styles();
    style                   = styles.add("Header");
    font                    = style.font();
    font.bold(true);
    font.color(255);
    sysExcelWorkSheets      = sysExcelWorkbook.worksheets();
    sysExcelWorkSheet       = sysExcelWorkSheets.add(null,null,1);
    sysExcelWorkSheet       = sysExcelWorkSheets.add();
    sysExcelWorkSheet.name('PayRegister');
    sysExcelWorksheet.cells().item(1,1).value('ItemId');
    sysExcelWorksheet.cells().item(1,2).value('NoOfPieces');
    sysExcelWorksheet.cells().item(1,3).value('scrap%');
    sysExcelWorksheet.cells().item(1,4).value('combination');
    sysExcelWorksheet.cells().item(1,5).value('selected');
    sysExcelWorksheet.cells().item(1,6).value('Generated');
    j=7;
    while select prodProfiles order by ItemLength where  prodProfiles.salesid == 'SO-100402'
                            &&   prodProfiles.ItemId == 'MSA05005'
    {
        sysExcelWorksheet.cells().item(1,j).value(prodProfiles.ItemLength);
        len[prodProfiles.ItemLength]  = j;
        j++;
    }
    sysExcelWorksheet.rows().item(1).style("Header");
    sysExcelWorksheet.columns().autoFit();
    sysExcelApplication.displayAlerts(false);
    sysExcelApplication.visible(true);
    k =2;
    while select scrTable order by LineNum  where scrTable.ItemId   == 'MSA05005'
                        &&   scrTable.SalesId  == 'SO-100402'
                        &&   scrTable.Selected == noyes::Yes
    {
        sysExcelWorksheet.cells().item(k,1).value(scrTable.ItemId);
        sysExcelWorksheet.cells().item(k,2).value(scrTable.NoOfPieces);
        sysExcelWorksheet.cells().item(k,3).value(scrTable.ScrapPercent);
        sysExcelWorksheet.cells().item(k,4).value(scrTable.NoOfCombinations);
        sysExcelWorksheet.cells().item(k,5).value(enum2str(scrTable.Selected));
        sysExcelWorksheet.cells().item(k,6).value(enum2str(scrTable.Generated));
        while select scrLines where scrLines.ItemId   == 'MSA05005'
        &&   scrLines.SalesId  == 'SO-100402'
        &&  scrLines.RefLineNum == scrTable.LineNum
        {


            sysExcelWorksheet.cells().item(k,len[scrLines.Length]).value(scrLines.NoOfPieces);
        }
        k++;
    }
}

Tuesday 19 July 2011

Date Calculation

Date Calculation :

static void DateCalcu(Args _args)
{
    TransDate   fromDate,toDate;
    int         reqDays;
    ;
  
    fromDate    = mkdate(01,07,2011);
    toDate      = mkdate(19,06,2011);
  
    if(fromDate && (toDate > fromdate))
    {
        reqDays = todate - fromDate;
    }
    else
    {
        throw error(strfmt("To-date %1 must be greater than from-date %2",todate,fromdate));
    }
    info(strfmt("%1",reqDays));
}

Thursday 14 July 2011

to filtering form by the enum values(which is n't shown in form)

suppose they are 3 field in enum one value is shown in form and another form is used in another form .we put the filter in datasource-->init method write the following code.
this.query().dataSourceTable(tablenum(inventtable)).addRange(fieldnum(inventtable,lltype)).value(enum2str(lltype::Both));

find and exit methods in tables

Exist Method:
static boolean exist(ItemId  itemId)--->this is key which is primary
{
    return itemId && (select RecId from inventTable -->table name
                index hint ItemIdx--->index name in table
                where inventTable.ItemId == itemId
                ).RecId != 0;
}
Find Method:
static InventTable find(ItemId      itemId,
                        boolean    update = false--->to define how many primarykeys in table )
{
    InventTable  inventTable;
    ;
    inventTable.selectForUpdate(update);
    if (itemId)
    {
        select firstonly inventTable-->table name
            index hint ItemIdx-->index name
            where inventTable.ItemId == itemId;
    }
    return inventTable;
}

Wednesday 6 July 2011

display records from different company accounts in one form

display records from different company accounts in one form

One of the previous posts on this blog discussed getting records from different company accounts with one select statement. For this, the crossCompany keyword is used.
Now we'll do something similar, but this time we'll display the records in a form. And the good news is, it's really easy. All ya have to do, is set a property on the datasource of the form.

You can use the crossCompanyAutoQuery property, located on the forms datasource. Standard value is 'No', so set it to 'Yes'

control:: enum on forms


control:: enum on forms

A somewhat non-intuitive way of accessing controls on a form is using a built in enum named ‘control’. This enum automatically contains all controls of you form (tabs, buttons, etc), and you can reference them by name.
So, if for example your button is called ‘ButtonFunctions’, you can set the property ‘enabled’ to false like this:
element.control (Control::ButtonFunctions).enabled (false);
The main advantage here is that you don’t have to set the property autodeclaration to yes

Rename an AX company on SQL


Rename an AX company on SQL
A while ago, I talked about deleting an AX company on SQL, but of course, you can also use the sp_MSforeachtable stored procedure to rename a company (= change the DataAreaId of a company).
In the next example, I rename CEE to CEA:
exec sp_MSforeachtable ‘update? set DataAreaID = "CEA" where? DataAreaID = "CEE"'

UPDATE DataArea SET ID = 'CEA' WHERE DataArea.ID = 'CEE'
UPDATE CompanyDomainList SET CompanyID = 'CEA' WHERE CompanyID = 'CEE'