29 September 2010

How to Use Temporary tables in reports

Ex:1 Report with datasource added
//Take a Report and Add a Table.
//Make sure that Table Properties set as "Temporary: YES" or
//In Report init method write this code "Tmtab.setTmp();" to make tamp
//Write the following code in the report Fetch Method

public boolean fetch()
{
str acc;

boolean ret;
// ret = super();
while select custTable
{
Tmtab_1.CustAccount = custTable.AccountNum;
Tmtab_1.doInsert();
this.send(Tmtab_1);
}
return true;
}
Ex:2 Report without Datasource
Step:1
Write the below code in fetch method
public boolean fetch()
{
str acc;

boolean ret;
// ret = super();
while select custTable
{
Tmtab.CustAccount = custTable.AccountNum;
Tmtab.doInsert();
//this.send(Tmtab);
element.execute(1);
}
return true;
}
Step:2
Create a display method and return the field value
//BP Deviation Documented
display CustAccount acc()
{
return Tmtab.CustAccount;
}

Working with Temporary Tables in forms

Ex: 1 Temp Table in Job
-----
static void tempTableData(Args _args)
{
CustTable custTable,tmpCustTable;
;
// Here setting custtable as Temprorary Table
tmpCustTable.setTmp();

while select custTable
{
//Here we are puting data to tempTable
tmpCustTable.data(custTable.data());
//printing tmpCustTable data
info(tmpCustTable.AccountNum);
}
}
----
Ex 2: Forms with datasource added
//Take a Form and Add a Table.
//Make sure that Table Properties set as "Temporary: YES" or
//In Form init method write this code "Tmtab.setTmp();" to make tamp
//Write the following code in the Form DataSource init() Method

public void init()
{
super();

while select custTable
{
TempTab.CustAccount = custTable.AccountNum;
TempTab.doInsert();
}
}

Ex 3: Forms without datasource added

.
.
.
Soon

28 September 2010

Using DictTable

static void dictTable_Ex(Args _args)
{
DictTable dictTable;
DictField dictField;
TableId tableId;
FieldId fieldId;
;

tableId = tablenum(CustTable);
dictTable = new DictTable(tableId);

if(dictTable)
{
fieldId = dictTable.primaryKeyField();

if(0 != fieldId)
{
dictField = new DictField(tableId, fieldId);
if(dictField)
{
print strfmt("Primary key field name: %1", dictField.name());
pause;
}
}

}
}

Write EXCEL Document, export data to excel with X++

static void CreateExcelDocument (Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
CustTable custTable;
int row = 1;
str fileName;
;

// Name of the Excel document.
fileName = "C:\\test.xslx";

// Excel open and initialize.
xlsApplication = SysExcelApplication:: construct ();
xlsApplication.visible (true);

// Create an Excel Worksheet produce.
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum (1);




// Write to the worksheet cells headings.
xlsWorkSheet.cells (). item (row, 1). value ('Account Number');
xlsWorkSheet.cells (). item (row,2). value ('name');

row ++;

// Excel Worksheet with data fill / (Excel cells fill).
while select custTable
{
xlsWorkSheet.cells (). item (row, 1). value (custTable.AccountNum);
xlsWorkSheet.cells (). item (row, 2). value (custTable.Name);
row ++;
}

// Check whether the document already exists.
if (WINAPI:: fileExists (fileName))
{
Winapi:: DeleteFile (fileName);
}

// Save Excel document.
xlsWorkbook.saveAs(fileName);

// Close Excel.
xlsApplication.quit ();
xlsApplication.finalize ();
}

22 September 2010

Convert date type to datetime type in ax

static void convertDateToDateTime(Args _arg)
{
date d = today();
int timeOfDay;
UTCDateTime datetime;
;
timeOfDay = str2time('00:00:00');
datetime = DateTimeUtil::newDateTime(d, timeOfDay);
pause;
}

15 September 2010

Code To Copy Table records between Companies, crosscompnay

static void Transfer_Rec(Args _args)
{
DictTable dicttable;
DictField dictfield;
Common common,common1;
int fieldcnt,i;//Returns the number of fields for the table
fieldId fieldid; //Field from usertable
UserTable TempTable,TempTable1; // UserTable is the table, whose data u want to copy

;

while select TempTable
{
common = TempTable;
dicttable = new DictTable(common.TableId);
changeCompany("tst")
{
TempTable1 = null;
common1 = TempTable1;
fieldcnt = dicttable.fieldCnt();
for (i = 1; i <= fieldcnt; i++)
{

fieldid = dicttable.fieldCnt2Id(i);
dictfield = new dictfield(common.TableId,fieldid);
if (dictfield.id() == fieldname2id(common.TableId,identifierstr(dataareaid)))
continue;
else
common1.(dictfield.id()) = common.(dictfield.id());

}
common1.insert();
}

}
print strfmt('done');
pause;
}

14 September 2010

Microsoft Dynamics AX Frameworks

1. Runbase Framework
2. Batch Framework
3. Dialog Framework
4. Operation Progress Framework
5. NumberSequence Framework
6. SysLastValue Framework
7. AIF-Application Integration Framework
8. Wizard Framework
9. Infolog Framework
10.Unit Test Framework

Microsoft Dynamics AX Design Patterns

The Microsoft Dynamics AX design patterns listed below enable you to use existing code patterns
to resolve common design issues Click here

1. Instantiating Application Objects
2. Searching for Records
3. Searching for Multiple Occurrences
4. Parameter
5. static find Method
6. static exist Method
7. Pack-Unpack
8. Persistent Data Storage
9. Containers as Parameter Bags
10. Multi-selection
11. Partner Hooks
12. Use the Type System
13. Data Validation
14. Change Company
15. Storno
----

15.Change Company

static void main()
{
CustTable custTable;
;

// Assume that you are running in company 'aaa'.
changeCompany('bbb') // Default company is now 'bbb'.
{
custTable = null;
while select custTable
{
// custTable is now selected in company 'bbb'.
}
}
// Default company is again set back to 'aaa'.

changeCompany('ccc') // Default company is now 'ccc'.
{

// Clear custTable to let the select work
// on the new default company.
custTable = null;


while select custTable
{
// custTable is now selected in company 'ccc'.
}
}
// Default company is again 'aaa'.
}

13 September 2010

insert_recordset & update_recordset

insert_recordset

void copySQLDictionary2DictionaryLine()
{
SqlDictionary sqlDictionary;
;

ttsBegin;
insert_recordset bufferDictionary(tabId, fieldId, array,
name, sqlName, fieldType, strSize, shadow,
rightJustify, nullable, flags)
select tabId, fieldId, array, name, sqlName, fieldType,
strSize, shadow, rightJustify, nullable, flags
from sqlDictionary
where sqlDictionary.tabId > 0;
ttsCommit;
}
------
update_recordset

MyTable myTableBuffer;
;
update_recordset myTableBuffer
setting
field1 = 1,
field2 = fieldX + fieldY
where field1 == 0;

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...