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.



Friday, 19 September 2014

OPEN A FORM FROM INFOLOG USING X++ CODE

We have to open a form for particular record from infolog using x++ code,

Here main class "SysInfoAction_tablefield" is used.

Write a job and get that task,

static void FormFromInfolog(Args _args)
{
    CustTable custTable;
    select  custTable where custTable.AccountNum == "US-001";
    info(strFmt("%1",custTable.AccountNum),"",SysInfoAction_tablefield::newBuffer(custTable));
}

Here i have given CustTable record and get that CustTable Form using "SysInfoAction_tablefield".

The output screen is,

                                 Once you click the Record in the infolog then only it shows the Show"" Button.




Main Form


CURRENCY CONVERTER USING X++ CODE

We have to convert the currency from "Some other country to US Dollar" in Job,

Here  "CurrencyExchangeHelper" is the Main class for convert the currency.

Then   CurrencyCode,  AmountCur, AmountMst  are EDT elements.

static void CurrencyConvertor(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = "INR";
AmountCur amountCur = 500.00;
AmountMst amountMST;

currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt("%1",amountMST));
}

The Output Screen is,


Now it converts INR  to US Dollar.If you change the INR into EUR then it converts the currency EUR into US Dollar.

CREATING A NEW FORM USING X++ CODE IN JOB

Here we want to create new form using x++ code in job,

Here all of the Form classes(Form,FormRun.......) are system Documentation classes.These are predefined classes.

static void CreateFormThroughCode(Args _args)
{
   Args                                      args;
    Form                                       form;
    FormRun                                formRun;
    FormBuildDesign                  formBuildDesign;
    FormBuildControl                 formBuildControl;
    FormBuildTabControl           formBuildTabControl;
    FormBuildTabPageControl   formBuildTabPageControl;
    FormBuildGridControl         formBuildGridControl;
    FormBuildDatasource           formBuildDatasource;
    FormBuildStringControl       formString;  


    form = new Form();
    formBuildDatasource             =  form.addDataSource(tableStr(PurchTable));
    formBuildDesign                    = form.addDesign("design");
    formBuildTabControl             = formBuildDesign.addControl(FormControlType::Tab, "Tab");
    formBuildTabPageControl     = formBuildTabControl.addControl(FormControlType::TabPage,    "TabPage");
    formBuildGridControl            = formBuildTabPageControl.addControl(FormControlType::Grid, "Grid");
    formString                              = formBuildGridControl.addDataField(formBuildDatasource.id(),  
                                                        fieldNum(PurchTable, PurchId));
    formString.label("PurchId");
    formString                             = formBuildGridControl.addControl(FormControlType::Real,   "Korcomptenz");
    formString.label("Korcomptenz");


    args  = new Args();
    args.object(form);
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}

The output Screen is,