Thursday, 27 August 2015

Create Sales Order From Purch Order in Ax 2009

Creating  Sales Order from Purch Order :

void clicked()
{
    NumberSeq num;
    SalesTable salesTable;
    SalesId newSalesId;
    CustTable custTable;
    SalesLine salesLine;
    InventTable inventTable;
    ;
    //create sales table
    salesTable.clear();
    salesTable.initValue();
    breakpoint;
    num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
    newSalesId = num.num();
    if (salesTable::exist(newSalesId))
    {
    num.abort();
    checkFailed("@LIQ1977");
    checkFailed(strfmt("@LIQ1978", newSalesId));
    throw error("@SYS23020");
    }
    salesTable.SalesId = newSalesId;
    num.used();
    select * from custTable where custTable.AccountNum == PurchTable.OrderAccount;
    salesTable.CustAccount = custTable.AccountNum;
    salesTable.InvoiceAccount = custTable.InvoiceAccount;
    salesTable.SalesType = SalesType::Sales;
    salesTable.SalesStatus = SalesStatus::Backorder;
    salesTable.CurrencyCode = custTable.Currency;
    salesTable.CustGroup = custTable.CustGroup;
    salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::SalesLeadTime;
    salesTable.ReceiptDateRequested = PurchTable.ReceiptDateConfirmed;
    salesTable.ShippingDateRequested = PurchTable.ShippingDateRequested;
    salesTable.PurchOrderFormNum = "Test";
    salesTable.LanguageId = "EN-US";
    salesTable.DlvMode = PurchTable.DlvMode;
    salesTable.initFromCustTable();
    salesTable.DeliveryName = PurchTable.DeliveryName;
    salesTable.DeliveryStreet = PurchTable.DeliveryStreet;
    salesTable.DeliveryCity = PurchTable.DeliveryCity;
    salesTable.DeliveryZipCode =PurchTable.DeliveryZipCode;

    //Create Sales Order
    salesTable.insert();

    // Create Sales Order Line
    salesLine.SalesId = salesTable.SalesId;
    salesLine.initFromSalesTable(salesTable);
    externalItemId = PurchLine.ItemId;
    salesLine.ItemId = externalItemId;
    salesLine.SalesUnit = InventTable::find(salesLine.ItemId).salesUnitId();
    select * from inventTable where inventTable.ItemId == salesLine.ItemId;
    salesLine.initFromInventTable(inventTable);
    salesLine.InventDimId = PurchLine.inventDimId;
    salesLine.SalesQty = 1;
    salesLine.ConfirmedDlv = salesTable.ShippingDateConfirmed;
    salesLine.lineNum = SalesLine::lastLineNum(salesLine.salesId) + 1.0;
    salesLine.LinePercent = 10;
    salesLine.RemainInventPhysical = 1;
    salesLine.RemainSalesPhysical = 1;
    salesLine.DlvMode = salesTable.DlvMode;
    salesLine.SalesStatus = SalesStatus::Backorder;
    salesLine.setPriceDisc(inventDim);
    //Insert sales line items
    salesLine.insert();
    info(salesTable.SalesId);
    info("Sales Order Created");
    super();
}

Thursday, 2 July 2015

Import Text(Notepad) file data to AX Table

Import the records from Text file to Ax table in ax

static void ImportTextToAXTable(Args _args)
{
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
TextIO file;
NotepadTable notepadTable;
container con;
str conitem,conitem1,conitem2;
Filename filepath,fileType;
int i;
#File
dialog = new Dialog("Notepad Upload");
dialogFilename = dialog.addFieldValue(extendedTypeStr(FilenameOpen),filename,"File Name");
dialog.filenameLookupFilter([".txt", #AllFiles]);
dialog.filenameLookupTitle("Upload from Text File");
dialog.caption("Upload from text file");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
file = new TextIO(filename, #IO_READ);
file.inRecordDelimiter('\n');
file.inFieldDelimiter(',');
[filepath, filename, fileType] = fileNameSplit(filename);
if(fileType==".txt")
{
ttsbegin;
while(file.status() == IO_STATUS::OK)
{
con = file.read();
conitem = conpeek(con,1);
if(conItem!="0")
{
notepadTable.initValue();
notepadTable.Name=conpeek(con,1);
notepadTable.Integer=conpeek(con,2);
notepadTable.insert();
}
}
ttscommit;
}
else
{
        info("File shoule be .txt format");
}

USER CAN GIVE INPUT MANUALLY INTO LOOKUP FIELD IN AX

TASK:

In my Table I have serial number field in that I want to enter manually serial numbers not taken from lookup but at the same time i don't want to save in InventSerial Table but i need to save my input into current table.

Simple Steps:
In Table level methods,

public boolean validateField(fieldId _fieldIdToCheck)
{
    boolean ret;
    ;
    if (_fieldIdToCheck == fieldnum(CurrentTable,InventSerialId))
        ret = true;
    else
        ret = super(_fieldIdToCheck);
    return ret;
}

Sunday, 8 March 2015

Pass Parameter from Form to ListPage Using ListPageInteractionClass

Step 1:

Create a Form and add datasource.

Step 2:

Add a Button and write code under Clicked() method for passing parameter.


void clicked()
{
FormRun formRun;
Args args = New Args();
super();
args.name("SalesTableListPage");
args.record(SalesTable);
formRun = ClassFactory.formRunclass(args);
formRun.init();
formRun.run();
formRun.wait();
}

Step 3:

Write code in "SalesTableListPageInteraction" class Initializing() method.

public void initializing()

{

super();

SalesTable SalesTable11 ;

if(this.listPage().listPageArgs() && this.listPage().listPageArgs().externalRecord())

{
        SalesTable11 = this.listPage().listPageArgs().externalRecord();
        info("Success");
}

}

Tuesday, 17 February 2015

SSRS Report Using RDP,Contract,UIBuilder Classes in Ax 2012

SSRS Report Using RDP,Contract,UIBuilder Classes in Ax 2012


UI Builder Class is needed when you want to customize your dialog which pop ups when you open a Report. UI Builder Class helps you to add run time lookups and other controls on the dialog form.




Step 1:

Create a Query in AOT.

Step 2:

Add tables as datasource into the query.

Step 3:

Create a RDP Class.


ClassDeclaration:

[
SRSReportQueryAttribute(queryStr(CustTransReport)),
SRSReportParameterAttribute(classstr(RamaCustTransContract))
]
public class RamaCustTransDP extends SRSReportDataProviderBase
{
CustTrans custTrans;
CustTable custTable;
CustTransTmp custTransTmp;
AccountNum number,custaccount;
}

Create a new method():

getCustTransTmp():

[
SRSReportDataSetAttribute(tablestr(CustTransTmp))
]
public CustTransTmp getCustTransListtmp()
{
select custTransTmp;
return custTransTmp;
}


Call the Override ProcessReport() method:

ProcessReport():

[SysEntryPointAttribute]
public void processReport()
{

QueryBuildDataSource qbds;
QueryBuildRange qbr;


RamaCustTransContract contract = this.parmDataContract() as RamaCustTransContract;
Query q = this.parmQuery();
QueryRun qr = new QueryRun(q);
qbds = qr.query().dataSourceNo(1).addDataSource(tablenum(CustTable));
number = contract.parmCustAccount();

while (qr.next())
{
custTable = qr.get(tablenum(CustTable));
custTrans = qr.get(tablenum(CustTrans));
IF(custTable.AccountNum == number)
{
custTransTmp.AccountNum = custTable.AccountNum;
custTransTmp.CustName = custTable.name();
custTransTmp.Voucher = custTrans.Voucher;
custTransTmp.Invoice = custTrans.Invoice;
custTransTmp.TransType = custTrans.TransType;
custTransTmp.TransDate = custTrans.TransDate;
custTransTmp.AmountCur = custTrans.AmountCur;
custTransTmp.RemainAmountCur = custTrans.remainAmountCur();
custTransTmp.insert();

}

}


Step 4:

Create Contract Class for Passing AccountNumber of the Customer:

ClassDecLaration:

[
DataContractAttribute,SysOperationContractProcessingAttribute(classstr(RamaCustTransUIBuilder))
]


public class RamaCustTransContract
{
CustAccount accountNum;
}


Create new method():


[
DataMemberAttribute('accountNum'),
SysOperationLabelAttribute(literalstr("Customer Id")),
SysOperationHelpTextAttribute(literalstr("Customer Id")),
SysOperationDisplayOrderAttribute("1")

]
public CustAccount parmCustAccount(CustAccount _custAccount = accountNum)
{
accountNum = _custAccount;
info("%1 contract class parmcustaccount",accountNum );
return accountNum;

}


Step 5:

Create UIBuilder Class for making Lookup in dialog.


ClassDeclaration:

class RamaCustTransUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
RamaCustTransContract contract;
}

Override the build() method:

public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(RamaCustTransContract, parmCustAccount),contract);
}


Create new method():



private void CustAccountLookup(FormStringControl formstringcontrol)
{
Query query = new Query();
QueryBuildDataSource qbds;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), formstringcontrol);
sysTableLookup.addLookupfield(fieldNum(CustTable,AccountNum));
qbds = query.addDataSource(tableNum(CustTable));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

}

override the getFromDialog() method:


public void getFromDialog()
{
contract = this.dataContractObject();
super();
}

Override the Postbuild() method:


public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(RamaCustTransContract,parmCustAccount));
dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(RamaCustTransUIBuilder,CustAccountLookup), this);
dialogEmplId.lookupButton(2);
}







Monday, 2 February 2015

DATA MIGRATION FRAMEWORK IN AX

Here,

            Sample Document  for Data Migration Framework. It is easy understandable and useful for ax beginners.

Click Here.....




                   

HOW TO USE EVENT HANDLER IN AX

Here,

                   We have a wonderful blog that use of Event Handler in Ax.Follow this blog its easy understandable for ax beginners.

CLICK HERE.....