Selasa, 19 April 2011

Create Own Sequence Number at Ms.Dynamics Ax


spAXrrttaaaaaaaann!! ..

Gowd ... sometimes we need own Sequence Number for our form at Axapta.
so these is code from one of my friends Dwipa Rachmawan(Ms.Dynamics Ax Technical), these code produces the order Number Sequence for our form without enrolled in the system sequence number that already exists in Axapta.

Select one table n create a Method
public void nextTaxInterval()
{
EHCTAXValueAddSubGroup eHCTAXValueAddSubGroup;
;
Select maxof(TaxInterval)
From eHCTAXValueAddSubGroup
where eHCTAXValueAddSubGroup.TaxGroupId == this.TaxGroupId;
// where eHCTAXValueAddSubGroup.TaxSubGroupId != this.TaxSubGroupId;
This.TaxInterval = eHCTAXValueAddSubGroup.TaxInterval + 1;

}

n then at form that contain with that datasource/table, generate Create method
public void create(boolean _append = false)
{
super(_append);
EHCTAXValueAddSubGroup.nextTaxInterval();
//assetDepreciationProfileSpec.nextInterval();
}

Senin, 04 April 2011

Melempar record-record ke Kolom2 Excel dalam Axapta


spAXrrttaaaaaaannn!! ..

Waktu tahun 2002-2003 aku pernah dalam project Human Resource dan ada sebuah script yang melempar data-data/record-record ke file Excel ...

void clicked()
{
CustTable CustTableSelected; //buffor to store the selected
COM excelApplication;
COM excelWorkBooks;
COM excelWorkBook;
COM excelWorkSheets;
COM excelWorkSheet;
COM range;
int lineNum;
Array arr;
;

excelApplication = new COM("excel.application");
excelWorkBooks = excelApplication.workBooks();
excelWorkBook = excelWorkBooks.add();
excelWorkSheets = excelWorkBook.worksheets();
excelWorkSheet = excelWorkSheets.add();
excelApplication.visible(TRUE);

super();

for (CustTableSelected = CustTable_ds.getFirst(true) ?
CustTable_ds.getFirst(true) : CustTable_ds.cursor(); CustTableSelected;
CustTableSelected = CustTable_ds.getnext())
{
lineNum++;
arr = new Array(Types::String);
arr.value( 1, custTableSelected.AccountNum);
arr.value( 2, custTableSelected.Name);
arr.value( 4, custTableSelected.CustGroup);

range = excelWorkSheet.Range(strfmt("A%1:D%1", lineNum));
range.value2(COMVariant::createFromArray(arr));
}
}

source code diatas sebenarnya bukan dari yang aku punya tapi aku dapat dari http://snippets.dzone.com/tag/Axapta

oh iya ini hasil Editan saya

void clicked()
{
CustTable CustTableSelected; //buffor to store the selected
COM excelApplication;
COM excelWorkBooks;
COM excelWorkBook;
COM excelWorkSheets;
COM excelWorkSheet;

COM rangetit;
COM range;

int lineNum;
int linetit;

Array arr;
Array arrtit;
int i=1;
;

excelApplication = new COM("excel.application");
excelWorkBooks = excelApplication.workBooks();
excelWorkBook = excelWorkBooks.add();
excelWorkSheets = excelWorkBook.worksheets();
excelWorkSheet = excelWorkSheets.add();
excelApplication.visible(TRUE);

super();
/*
for (CustTableSelected = CustTable_ds.getFirst(true) ?
CustTable_ds.getFirst(true) : CustTable_ds.cursor(); CustTableSelected;
CustTableSelected = CustTable_ds.getnext())
{
lineNum++;
arr = new Array(Types::String);
arr.value( 1, custTableSelected.AccountNum);
arr.value( 2, custTableSelected.Name);
arr.value( 4, custTableSelected.CustGroup);

range = excelWorkSheet.Range(strfmt("A%1:D%1", lineNum));
range.value2(COMVariant::createFromArray(arr));
}
*/
lineNum = i;


linetit++;
arrtit = new Array(Types::String);
arrtit.value(1,"Account");
arrtit.value(2,"Name");
arrtit.value(4,"Group");
rangetit = excelWorkSheet.Range(strfmt("A%1:D%1", linetit));
rangetit.value2(COMVariant::createFromArray(arrtit));

while select CustTableSelected
{
lineNum++;
arr = new Array(Types::String);
arr.value( 1, custTableSelected.AccountNum);
arr.value( 2, custTableSelected.Name);
arr.value( 4, custTableSelected.CustGroup);

range = excelWorkSheet.Range(strfmt("A%1:D%1", lineNum));
range.value2(COMVariant::createFromArray(arr));
}

}

lookup berdasarkan Parameter-nya


spAXrrttaaaaaaaaaaaaann!! ...

Method Lookup disini adalah sebuah method yang banyak dipakai dalam membangun/mengubah Applikasi di Microsoft Dynamics Ax ...

public void lookup()
{
//Lookup AttachmentCode berdasarkan TaxTrans
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
// Create an instance of SysTableLookup where 'this' the current Form control.
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(IBMTaxAttachment), This);
;
// The field to be shown in the lookup form.

sysTableLookup.addLookupField(fieldNum(IBMTaxAttachment, IBMTaxAttachmentCode));
sysTableLookup.addLookupField(fieldNum(IBMTaxAttachment, Description));

// Limit and arrange data selection.
queryBuildDataSource = query.addDataSource(tableNum(IBMTaxAttachment));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(IBMTaxAttachment, IBMTaxTransCode));

queryBuildRange.value(Grid1_IBMTaxTransCode.valueStr());
sysTableLookup.parmQuery(query);
// Perform lookup
sysTableLookup.performFormLookup();
}

Erorr CS1963 - An expression tree may not contain a dynamic operation.

Kali ini saya mendapatkan erorr dengan code CS1963, padahal sebelumnya saya sudah mendefinisikan 'var item in Model' di @foreach(var...