Showing posts from May, 2013

Creating Vendors through X++ in AX 2012- PART IV

Creating Vendors through X++ in AX 2012- PART IV

--Create contact for the vendor--

privatevoid createContact(VendorRequestCreate       _vendorRequestCreate,
                           RefRecId                     _partyId) 
    ContactPerson           contactPerson;
    DirPersonName           lDirPersonName;
    DirPerson               lDirPerson;
    DirParty                lDirParty;
    LogisticsLocation       lLogisticsLocation;
    DirPartyContactInfoView             lDirPartyContactInfoView; 
//Create party for Contact
    lDirPerson.Name                          = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameAlias                     = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameSequence                  = dirNameSequence::find('First Last').RecId;
    lDirPersonName.FirstName                 = _vendorRequestCreate.ContactPersonName;
//lDirPersonName.MiddleName                = _vendorRequestCreate.ContactPersonName;

Custom lookup for Dialog fields in Axapta [AX2012]

Custom lookup for Dialog fields in Axapta

Overriding the event methods (e.g. custom lookup, modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!
In order to override the event methods on dialog controls, the following needs to be done.
class TestDialogFields
    Dialog                   dialog;  
    DialogField           newProdIdField;
public static void main(Args args)
    TestDialogFieldstestDialogFields = new TestDialogFields();
     DialogRunbase               dialogRunbase;
    dialogRunbase = DialogControlOverload.showDialog();
        // code for update  once the use selects a record from the lookup and click 'ok'
Dialog showDialog()
    FormRun     formRun;
    dialog = new Dialog('Dialog fields test');
    newProdIdField = dialog.addField(typeId(ProdId));;

How to Read/Write an Excel file through X++ code

How to write an Excel file through X++ codeIn This Post you will found two code sample
1.Write data in excel through X++ code.
2. Read from an Excel through X++ code

1.Write data in excel through X++ code.

static void thaAxapta_Write2Excel(Args _args)

InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cell = cells.item(1,1);
cell = cells.item(1,2);
row = 1;
while select inventTable
    cell = cells.item(row, 1);
    cell = cells.item(row, 2);

Multiple Tables In Query

Axapta query on multiple tables

Hey friends try this code to add multiple tables in query.
QueryRun selectReportQuery() {     Query                   query           = new Query();     QueryRun                localQueryRun;     QueryBuildDataSource    qbds1;     QueryBuildDataSource    qbds2;     QueryBuildDataSource    qbds3;     ;     qbds1 = query.addDataSource(tableNum(salesTable));     qbds1.addRange(fieldNum(salesTable, affVendorAdjust)).value('1');     qbds2 = qbds1.addDataSource(tableNum(custInvoiceJour));     qbds2.fetchMode(JoinMode::InnerJoin);     qbds2.relations(false);     qbds2.addLink(fieldNum(salesTable, salesId),fieldNum(custInvoiceJour, salesId));     qbds2.addSortField(fieldNum(CustInvoiceJour, OrderAccount), SortOrder::Ascending);     qbds2.addSortField(fieldNum(CustInvoiceJour, InvoiceId), SortOrder::Ascending);     qbds2.addRange(fieldNum(CustInvoiceJour, InvoiceDate)).value(queryRange(invBeginDate, invEndDate));     qbds3 = qbds1.addDataSource(tableNum(salesLine));     qb…

Cannot execute a data definition language command on (). The SQL database has issued an error.

Cannot execute a data definition language command on  ().
The SQL database has issued an error.

Suggested Solutions:

Creating Vendors through X++ in AX 2012- PART III

Creating Vendors through X++ in AX 2012- PART IIICreating Vendors through X++ in AX 2012- PART I Creating Vendors through X++ in AX 2012- PART II --Create postal address--

publicvoid createPostalAddress(VendorRequestCreate          _vendorRequestCreate)
    VendorRequestAddress             vendorRequestAddress;
    DirPartyPostalAddressView           dirPartyPostalAddressView;
select Addressing, LogisticsAddressCity, LogisticsAddressCountryRegionId, LogisticsAddressStateId,
            LogisticsAddressZipCodeId from vendorRequestAddress
where vendorRequestAddress.WI_VendorRequestCreate       == _vendorRequestCreate.RecId;
// Create postal address
if(dirPerson.RecId || dirOrganisation.RecId)
        dirPartyPostalAddressView.LocationName                  = 'Primary business';
        dirPartyPostalAddressView.Address                       = vendorRequestAddress.Addressing;
        dirPartyPostalAddressView.City                          = vendorRequestAddress.LogisticsAddressCity;

Error: Cannot create a record in Balance (CustVendTmpOpenTransBalances). Currency: , 0,00.The record already exists

Error: Cannot create a record in Balance (CustVendTmpOpenTransBalances). Currency: , 0,00.The record already exists Hi all,
I found a good form post for the same error,
check this link
Error: Cannot create a record in Balance (CustVendTmpOpenTransBalances). Currency: , 0,00.The record already exists

X++ Code to Create Purchase Order and Post the Invoice.

X++ Code to Create Purchase Order and Post the Invoice.Following code will create the Purchase order from code and post the invoice as well by making use of "PurchFormLetter" class.

static void TheaxaptaCreatePOInvoice(Args _args)

NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);
// Initialize Purchase order values
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount = '3000';
if (!Purchtable.validateWrite())
throw Exception::Error;
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchtable, // Purchase record Buffer

How to Enable/Disable fields in a dialog

How to Enable/Disable fields in a dialogIf you need to enable/disable the dialog fields use dialogpostrun method in your code.
here is a the some code sample for enable/disable dialog fields.

public void dialogPostRun(DialogRunbase _dialog)
// allow to call the event methods of this class (e.g. theaxapta1_modified() method)

Now you can create event methods on your dialog fields like theaxapta1.modified() where you can address other components in the dialog, and modify their properties as well.

public boolean theaxapta1_modified()
    FormStringControl   control = dialog.formRun().controlCallingMethod();
    boolean             isFieldModified;
    isFieldModified = control.modified();
// every time the employee id is changed,it will update the employee name