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:


FINDING ALL DATASOURCE IN A FORM THROUGH JOB

Code for finding datasources in a form..

static void AllDataSourcesInForm(Args _args)

{
    Args args = new Args();
    
    FormRun fr;
    
    FormBuildDataSource formBuildDataSource;
  
    counter i;
   
    ;
  
    args.name("VendTable");   // its your FORM name
   
    fr = ClassFactory.formRunClass(args);
  
    for(i=1 ; i<=fr.form().dataSourceCount();i++)
  
    {
   
       formBuildDataSource = fr.form().dataSource(i);
    
       info(new DictTable(formBuildDataSource.table()).name());
  
     }
}



LISTVIEWCONTROL IN DYNAMICS AX.

By using ListViewControl We have to see some functions,

1.How to select multiple records and shown from ListViewControl.

2.In ListViewControl how  to transfer multiple records from one  to another.

3.Inside the ListViewControl how to make Up and Down arrow Actions for that records.


Function 1:

Select Multiple records and shown in the infolog.

Step 1:

Create a new form(ListViewControl) and add the control ListView under Design node.



Step 2:

Change the properties for that control is Autodeclaration -->yes and viewtype-->report.



Step 3:

Mention the columns for that ListViewControl by using Init() method in form level,

public void init()
{

super();

LeftListView.addColumn(1, new FormListColumn("Customer AccountNumber"));

//LeftListView is Control Name.

}

Step 4:

Get the records from Somewhere.(Here I want to show all customer's account number. so I am taking
 records from custTable).

public void run()
{
CustTable custTable;
;
super();

// Adding items to the list
while select AccountNum from custTable
{
LeftListView.add(custTable.AccountNum);
}
}

Step 5:
Add a new button and put name as "selected records".Under this button write clicked() method for getting selected records in the infolog.

void clicked()
{
FormListItem item;
int i;
;

super();
i = LeftListView.getNextItem(FormListNext::Selected);
while (i != -1)
{
item = LeftListView.getItem(i);
info (item.text());
i = LeftListView.getNextItem(FormListNext::Selected,i);
}
}


Step 6:

       Now we complete the first function.




Function 2:

In ListViewControl how  to transfer multiple records from one  to another.

we have to follow some steps,,

Step 1:

Similar to first function put one more ListViewControl under design node.Set name as RightListView button.change the property as Autodeclaration-->yes and viewtype-->Report.

Step 2:

Add a new button and set name as MoveButton. Under this write clicked() method for transfer records from one control to another ListView, At the same time the transfer records should delete from first ListViewControl.

void clicked()
{
FormListItem item;
int i;
;

super();
i = LeftListView.getNextItem(FormListNext::Selected);
while (i != -1)
{
item = LeftListView.getItem(i);
RightListView.addItem(item);                      //Add items 
LeftListView.delete(i);      // Delete the selected item  from the LeftListView            i = LeftListView.getNextItem(FormListNext::Selected);
}
}

Step 3:

Now we complete the second function.




Function 3:

Inside the ListViewControl how to make Up and Down arrow Actions for that records.

Step 1:

Add two more buttons in the form.Set name as "ÜpButton" and "DownButton".Write the single line code for that buttons under clicked() method.

Code for move the item Upwards,

void clicked()
{
int i = LeftListView.getNextItem(FormListNext::Selected); 

LeftListView.moveItem(i, i-1);





Code for move the items Downwards,

void clicked()
{
int i = LeftListView.getNextItem(FormListNext::Selected); 

LeftListView.moveItem(i, i+1);





Step 2:

       We complete the third function also.