Popular Posts

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'