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.....




Wednesday, 21 January 2015

Post a Ledger Journal in AX 2009 using X++

Here,

                   We have a wonderful blog for posting ledger journal through X++ code..Follow this blog its easy understandable for ax beginners.

CLICK HERE....

Thursday, 8 January 2015

DEVELOPING SSRS REPORT WITH CHART USING RDP CLASS

DEVELOPING SSRS REPORT WITH CHART USING RDP CLASS

Here,

                   We have a wonderful blog for Developing a SSRS report with chart using the Report Data Provider...Follow this blog its easy understandable for ax beginners.

Click Here......

Wednesday, 7 January 2015

DEVELOPING SSRS REPORT USING AX ENUM PROVIDER


Developing SSRS Report using Ax Enum Provider

Step 1:

Create a Query in AOT.
 
 

Step 2:

Add a datasource(SalesTable) into a Query and Set a Range for particular Enum(SalesStatus).

Step 3:

Now open Visual Studio and create new project.

Step 4:

Similarly add dataset into the report and set the property datasourcetype-->Query , Query-->Our Query Name.

Step 5:

Again add one more dataset and set datasourcetype-->Ax Enum provider , Query-->Our Enum Name(SalesStatus).
 
 
 
Step 6:

Drag and Drop the first dataset into design node.
 
 
 
 
    Finally Deploy the Report into AOT.
 
    We will get the output...
 
 


Sunday, 4 January 2015

HOW TO USE THE PAYMENT JOURNAL IN THE AP MODULE

We have a wonderful blog for using payment journal in the accounts payable module in ax 2012 .....
    
 Follow this blog its easy understandable for ax beginners.


Click Here.....

 

Monday, 29 December 2014

ENABLE OR DISABLE THE ROWS IN GRID based On CHECKBOX

STEP 1:

Create a Table with Some Fields.Add all fields into FieldGroup except CheckBox Field.



STEP 2:

Creae a Form and add a table as Datasource.



STEP 3:

Drag and drop the Group and CheckBox Field into Design node.

STEP 4:

Write a code in CheckBox  Control level modified() method:

public boolean modified()
{
    boolean ret;

    EnableDisableRows enableDisableRows11;

    ret = super();

    if(this.value()==boolean::false)
    {
        Group1.enableChilds(true);
    }
    else
    {
        Group1.enableChilds(false);
    }

    return ret;
}

STEP 5:

We can get the output,,

 
 





 

Monday, 22 December 2014

SET BACKGROUND COLOR FOR PARTICULAR RECORD

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    if (_record.(fieldnum(Contributions,Year))=="2011")
    {
     _options.backColor(WinAPI::RGB2int(500,100,255));
    }
    else if(_record.(fieldnum(Contributions,Year))=="2014")
   {
     _options.backColor(WinAPI::RGB2int(101,100,255));
    }

    super(_record, _options);
}


 
BASED ON SALESID GET PRIMARY PHONE NUMBER AND ADDRESS

static void TestJob(Args _args)
{
str a; 
SalesTable salestable;
LogisticsLocation logisticslocation;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsPostalAddress logisticsPostalAddress;
select salestable where salestable.salesid=='001731';
select logisticslocation where logisticslocation.ParentLocation ==LogisticsPostalAddress::findRecId(salestable.DeliveryPostalAddress).Location;
info(LogisticsElectronicAddress::findByLocation(logisticslocation.RecId).Description);  
info(LogisticsElectronicAddress::findByLocation(logisticslocation.RecId).Locator);
}

 
BASED ON CUSTOMER GET PRIMARY PHONE NUMBER AND ADDRESS

static void TestJOb(Args _args)
{
CustTable custTable;
DirPartyPostalAddressView  dirPartyPostalAddressView ;
LogisticsEntityLocationView  logisticsEntityLocationView ;
LogisticsLocation logisticsLocation ;
LogisticsElectronicAddress logisticsElectronicAddress;
str aa;
select custTable where custTable.AccountNum=="US-005";
info(custTable.address());
aa=custTable.address();
while  select dirPartyPostalAddressView
{
if(dirPartyPostalAddressView.Address==aa)
{
select logisticsEntityLocationView  where logisticsEntityLocationView.EntityLocation==dirPartyPostalAddressView.RecId;
select logisticsLocation where logisticsLocation.ParentLocation==logisticsEntityLocationView.Location;
select logisticsElectronicAddress where logisticsElectronicAddress.Location==logisticsLocation.RecId;
info(logisticsElectronicAddress.Description);
info(logisticsElectronicAddress.Locator);
}
}

}

 

Friday, 19 December 2014


Passing Multiple Records from Form to Report

Step 1: Input Form: Create an Input Form as given Below this will act as first step.





Step 2: Button Clicked: Create a Button which will contain a clicked method which can help in transferring data(records) from form to reports.

void clicked()
{
CustTable    custTable1;
container    con;
Args            args;
str               multiSelectString;

ReportRun reportRun;

args = new Args();

while select custTable1 where custTable1.Checker==boolean::true
{

//Checker is our field

con = conIns(con,1, custTable1.AccountNum);

multiSelectString = con2Str(con, ',' );

}


args.parm(multiSelectString);

args.name(reportstr(ReportCusty_GV));

//ReportCusty_GV is Report Name.

reportRun = classFactory.reportRunClass(args);
reportRun.init();
reportRun.run();
}


Step 3: Create a Report with necessary designs.

Step 3.1: Init Method: Write the below mentioned code in init() method to get values from the form.


public void init()
{
str multipleRecords;

super();

multipleRecords = element.args().parm();
this.query().dataSourceTable(Tablenum(CustTable)).addRange(fieldNum(CustTable,AccountNum)).value(multipleRecords);


}
































EDIT AND DISPLAY METHODS IN AX 2012


EDIT METHOD:


Edit CustAccount custItemGroupId(boolean _set , CustAccount _custItemGroupId)
{
CustTable custTable;
;
if(_set)
{
if(_custItemGroupId)
{
ttsbegin;
custTable = CustTable::find(this.ID,true);
                                         // this mention our Table and ID is  our field
custTable.AccountNum = _custItemGroupId;
custTable.update();
ttscommit;
}
}
else
{
_custItemGroupId = CustTable::find(this.ID).AccountNum;
}
return _custItemGroupId;
}


DISPLAY METHOD


Display CustAccount custItemGroupId1 ()
{
CustTable custTable;
;
return CustTable::find(this.ID).AccountNum;
}

Monday, 10 November 2014

Based on Barcode Populating Item Details Including Dimensions in TransferLine

Based on Barcode populate Item Details including Dimensions in TransferLine

Note:

The bar code for each item is available in the "InventItembarcode" table and refer this table to understand about "bar code".

Steps:

1.create a new field "barcode" in InventTransferTable table and drag and drop the field into table grid in the InvenTransferOrders form.




2.Craete the same field in InventTransferLine table also ,and drag and drop the field into table grid in the InvenTransferOrders form.

3.When we select a new barcode in the header table, All item details will be populated and the same will be inserted as new line in the transfer screen including all the dimensions like color, size and serial numbers.

It is possible to add multiple lines for the same transfer order [same item can also be inserted with different bar code]




4.If the selected bar code is already used by the same or any other transfer orders,
  then it should prompt an error with that existing transfer order number [Eg:"The bar code is already    exist in the Transfer order 000008"]



5.The bar code field in the header should be empty each time after the selection of bar code .

6.So write the code in the Modified() method of the barcode field in Datasourse "InventTransferTable"


public void modified()
{
    InventTransferTable _inventTransferTable;
    InventTransferLine line,line1;
    InventItemBarcode _InventItemBarcode;
    InventDim inventDim1;

    super();


         if(InventTransferTable.itemBarCode)

          {
                 if(InventTransferTable.validateWrite())

                   {
                     select _InventItemBarcode where                      _InventItemBarcode.itemBarCode==InventTransferTable.itemBarCode;

                           if(_InventItemBarcode)

                            {

                             line.initValue();

                             line.initFromInventTableModule(InventTableModule::find(line.ItemId,ModuleInventPurchSales::Invent));

                             line.initFromInventTransferTable(InventTransferTable,true);

                             line.itemBarCode=_InventItemBarcode.itemBarCode;

                             line.ItemId=_InventItemBarcode.itemId;

                             line.LineNum=InventTransferLine::lastLineNum(InventTransferLine.TransferId)+1.0;

                             select InventDim where InventDim.inventDimId==_InventItemBarcode.inventDimId;

                             line.InventDimId=InventDim.inventDimId;

                                               if(line.validateWrite())

                                                 {
                                                   select ItemBarCode from line1 where line1.itemBarCode==line.itemBarCode ;

                                                      if(!line1)
                                                        {
                                                            line.insert();
                                                        }
                                                      else
                                                        {
                                                           InventTransferTable.itemBarCode = " ";
                                                           select TransferId from line1 where line1.itemBarCode ==           line.itemBarCode;
                                                           throw error("Barcode Already Exist in Transfer Order"+"   "+ line1.TransferId);
                                                        }

                                                  }

                               }


                      }

              InventTransferTable.itemBarCode = " ";

              InventTransferLine_ds.executeQuery();


       }


}


Now you can run the form and get the output.....................................



Tuesday, 21 October 2014

UPDATING THE PRODUCT ATTRIBUTE FOR PARTICULAR PRODUCT FROM EXCEL

By using job we update the product attributes for particular product in product information management module.

static void excelattribute(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    FilenameOpen  filename;
    EcoResAttributeGroupAttribute ecoResAttributeGroupAttribute;
    EcoResProduct  ecoResProduct ;
    EcoResProductCategory ecoResProductCategory;
    EcoResCategory ecoResCategory;
    EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
    EcoResAttribute ecoResAttribute;
    EcoResAttributeType ecoResAttributeType;


    int row ;                   // if the excel has the header
    str attribute ,attribute1;
    str attribute2;
       
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();

    filename  = "C:\\Users\\charlie\\Desktop\\RamaProductAttribute.xlsx"; // file path
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File not found");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    //Iterate through cells and get the values
    do
    {
 
    //Incrementing the row line to next Row
      row++;

        attribute              = cells.item(row, 1).value().bStr();
        attribute1              = cells.item(row, 2).value().bStr();
        attribute2              = cells.item(row, 3).value().bStr();          
           
     
/*Insert ProductAttribute values*/

        select ecoResAttributeType;
        ecoResAttributeType.Name=attribute1;
       
        ecoResAttributeType.DataType=any2int(str2enum(AttributeDataType::Decimal,attribute2));
        ecoResAttributeType.insert();
        select ecoResAttribute;
        ecoResAttribute.Name=attribute;
        if(ecoResAttribute.AttributeType)
        ecoResAttribute.AttributeType=ecoResAttributeType.RecId;
        
        ecoResAttribute.insert();

/* assign above productAttributes to "0117" product*/

    select ecoResProduct join ecoResProductCategory join ecoResCategory join                                 

ecoResCategoryAttributeLookup join ecoResAttribute  join ecoResAttributeType  where 

ecoResProduct.DisplayProductNumber=="0117" && 

ecoResProductCategory.Product==ecoResProduct.RecId     && 

ecoResCategory.RecId==ecoResProductCategory.Category;

    if(ecoResCategoryAttributeLookup)

    ecoResCategoryAttributeLookup.Category=ecoResCategory.RecId;

    while   select Name from ecoResAttribute

     if(ecoResAttribute.Name==attribute)
       
    {

     ecoResCategoryAttributeLookup.Attribute=ecoResAttribute.RecId;
           
     while select Attribute from ecoResAttributeGroupAttribute
                 
      if(ecoResAttributeGroupAttribute.Attribute== ecoResCategoryAttributeLookup.Attribute)          
               
            ecoResCategoryAttributeLookup.AttributeGroupAttribute=ecoResAttributeGroupAttribute.RecId;
     
      ecoResCategoryAttributeLookup.insert();

       }

       while select ecoResAttribute where

       ecoResAttribute.RecId==ecoResCategoryAttributeLookup.Attribute

     //  if(ecoResAttribute.RecId==ecoResCategoryAttributeLookup.Attribute)
 
         {
   
         info(ecoResAttribute.Name);
     
         }


     // Loads the next row into the variant type and validating that its is empty or not
 
       type = cells.item(row+1, 1).value().variantType();
     
       }
   
       while (type != COMVariantType::VT_EMPTY);

     // quits the application
 
       application.quit();    


}

Here we should understand the table realtions.

1.EcoResProduct              

    // Here select the product to update product attribute

2.EcoResProductCategory    

 // EcoResProductCategory.product==EcoresProduct.RecId

3.EcoResCategory                

  // EcoResCategory .RecId==EcoResProductCategory.Category

4.EcoResCategoryAttributeLookup                                          

 // EcoResCategoryAttributeLookup.Category==EcoResCategory.RecId

5.EcoResAttribute            

  // EcoResAttribute.RecId==EcoResCategoryAttributeLookup.Attribute







Friday, 3 October 2014

OPEN A WEBPAGE IN SINGLE LINE THROUGH X++

 We already seen,by using ActiveX Control to  open the web page,

 Now without using ActiveX control how will get webpage...


  static void WebPage(Args _args)
  {
  infoLog.urlLookup('http://www.google.co.in'); //name of the page                                                                                 you want to open.
  } 


Output window: