Sunday 5 March 2017

Multiselect LookUp Filter

1.Create a Form  and add three fields in design node (Cust_acc , SalesId ,Itemid with their respective EDT)
Important Note: Form without datasource (it is possible)
2.Declare the multiselect  buffer in class declaration

public class FormRun extends ObjectRun
{
SysLookupMultiSelectCtrl sysLookupMultiSelectCtrl;
}

3.Create init method in form method
public void init()
{
Query query = new Query();

QueryBuildDataSource qbds; //SysLookupMultiSelectCtrl msCtrlCust;

super();

qbds = query.addDataSource(tableNum(CustTable)); //qbds = query.addDataSource(tableNum(SalesLine));
qbds.fields().addField(fieldNum(CustTable,AccountNum));
sysLookupMultiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(element, Cust_Account, query);

}
4.create modified method in custaccount field in design node
public boolean modified()
{
boolean ret;
ret = super();
Sales_Id.lookup();
return ret;
}
5.Next in SalesId field create lookup method
public void lookup()

{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;
str txt;
    //
qbds = query.addDataSource(tableNum(SalesTable)); qbds.fields().addField(fieldNum(SalesTable, SalesId)); qbds.fields().addField(fieldNum(SalesTable, CustAccount));
 qbds.fields().dynamic(NoYes::No);
qbr = qbds.addRange(fieldNum(SalesTable, CustAccount));
 qbr.value(Cust_Account.valueStr());
txt = strReplace(Cust_Account.valueStr(),";",",");
 qbr.value(txt);
SysLookupMultiSelectCtrl::constructWithQuery(element, Sales_Id, query);

}

6.Create lookup method in ItemId field
public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;

 str txt;
 qbds = query.addDataSource(tableNum(SalesLine));
 qbds.fields().addField(fieldNum(SalesLine, ItemId));
 qbds.fields().addField(fieldNum(SalesLine, SalesId));
 qbds.fields().dynamic(NoYes::No);
 qbr = qbds.addRange(fieldNum(SalesLine, SalesId));
 qbr.value(Sales_Id.valueStr());
 txt = strReplace(Sales_Id.valueStr(),";",",");
 qbr.value(txt);
 SysLookupMultiSelectCtrl::constructWithQuery(element, Item_Id, query);

}
7.Add modified method in same SalesId field
public boolean modified()
{
boolean ret;
ret = super();
Item_Id.lookup();
return ret;
}

 It will be filtered according to the custaccount next salesid and item id











Display Method in AX2012

  1. Create Two Tables  with fields (Customername, Itemname, Amount - Table1,Customername, Name ,Qty - Table2 ) 














2.After  that create a form with datasource
3.Add the fields in  design node.
4.Create  a new method in table you want to display(i.e Display  the  itemname in the name field of Table2)

Display ItemName Test()
{
    Display2 display2;
    Display1 display1;
    //ItemName name;
 select display2 where display2.CustomerName== this.CustomerName;
 return display2.ItemName;
}















5.Now go to Form -> Design Node-> Name field  properties  DATASOURCE  as Table2 & DATA METHOD  as Test() method name














6.Now you can see the output  i am getting the Item name in my Name field

Thursday 2 March 2017

Argument Passing from ListPage to another form

  1. First Create Two tables  header and line  
  2. Create Two forms as header (ListPage) and line (Normal form) (listpage datasource  query must be created with two tables)
  3. In the header form and line form  add the respective datasource  i.e header and line table (in both the form)
  4. Create a menu item button in design node of Header Form  actionpane  and add a new method  in it(under the button ) 
  5. Link the menu item button with line table menuitem  (properties of menuitem button)
  1. Drag and drop the fields in the design node both the forms (grid  format) 
  2. Paste the code  below  in init method of line form 
public void init()
    {
          TestImport table1;
           super();
           table1 = element.args().record();
             TestImport_ds.query().dataSourceTable(Tablenum(TestImport)).addRange(fieldNum(table1,RecId)).
          value(SysQuery::value(table1.RecId));
        }
        • Open the header form and  click  the button you have created  after selecting the record in grid



        Important Note: screenshots based on my listpage   you can do it in  normal form also
         small difference is menu item button  in list page form  will be created
        in normal form  button is used





        final note: check the design field and button properties that are linked to the table

        Code for Import from Excel to AxTable


        1. First Create Two tables  header and line  
        2. Create Two forms as header and line 
        3. In the header form and line form  add the respective datasource  i.e header and line (in both the form)
        4. Create the xcel sheet  with you values according to the field in the table
        5. Create the job and paste the coding below  run it


        static void TestImport(Args _args)
        {

        SysExcelApplication application;
        SysExcelWorkbooks workbooks;
        SysExcelWorkbook workbook;
        SysExcelWorksheets worksheets;
        SysExcelWorksheet worksheet;
        SysExcelCells cells;

        int i;
        str com;
        COMVariantType type;
        FileName filename;
        TestImport header;
        TestImportline   line;
        int row;
        //int UnitQty;
        //int    VehicleNumber;
        //str AccountNumber;
        //str Name;
        //real Amount
        ;

        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        //specify the file path that you want to read
        filename = "G:\\Test.xlsx";
        try
        {
        workbooks.open(filename);
        }
        catch (Exception::Error)
        {
        throw error("File cannot be opened.");
        }

        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1); //Here 3 is the worksheet Number
        cells = worksheet.cells();
        do
        {
        row++;
        com = cells.item(row, 1).value().bStr();
        if(com!="0")
        {
        header.AccountNum=cells.item(row, 1).value().bStr();
        header.Name = cells.item(row, 2).value().bStr();
        header.Amount =(cells.item(row,3).value().double());
        header.insert();
            }
        if(conitem!="0")
            {
                line.AccountNum=  cells.item(row, 1).value().bStr();
                line.Amount= (cells.item(row,3).value().double());
                line.UnitQty= any2int(cells.item(row, 4).value().toString()); //(cells.item(row,4).value().int());
                line.VehicleNumber=any2int(cells.item(row, 5).value().toString());
                line.insert();
            }

        type = cells.item(row+1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
        application.quit();
        }