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,


HIDE SELECTED ENUM VALUES IN FORM CONTROL USING X++

I referred the blog  axwiki.blogspot.in and get this idea,

Main task is Removing some of the elements from Enum value that are not needed. Example WeekDays is one of the Enum in AX. It shows name of 7 days in the Week. Here I want to show only 3 days. How I do,

By using one of the Ax class "SysFormEnumComboBox" we can get.

We want to follow some steps:

Step 1:

Create a new form . Add a ComboBox control under design node in the form.Then set the property of control EnumType --> Weekdays and  AutoDeclaration-->Yes.



Step 2:

Write the code in form level  init() method,

public void init()
{
    SysFormEnumComboBox     sysFormEnumComboBox;
    Set enumSet = new Set(Types::Enum); // collection of selected values.

    enumSet.add(WeekDays::Monday);
    enumSet.add(WeekDays::Wednesday);
    enumSet.add(WeekDays::Friday);

    SysFormEnumComboBox =                     SysFormEnumComboBox::newParameters(element,

        element.controlId(formControlStr(HideEnumValue, HideEnumValueControl)),  enumName2Id(enumStr(WeekDays)), enumSet);


 super();

}

SynTax for SysFormEnumComboBox  is,

SysFormEnumComboBox::newParameters(FormRun _FormRun, ComBocontrolId,EnumId,set);

So  here,

HideEnumValue-->FormName
HideEnumValueControl-->ComBoxControlName
WeekDays-->BaseEnum
enumset-->Variable of Set.

The output Screen is,



RETRIEVING MULTIPLE SELECTED RECORDS FROM GRID USING X++.

We want to follow some steps....

Step 1:

Create a new Table(Multiselecttable).Add the fields lilke Name,IdNumber.



Step 2:

Insert some records into the Table.

Step 3:

Create a new Form(MultiSelectForm) and Add the table as a datasource  into the Form.

Step 4:

Drag and Drop the fields into Grid under design node.

Step 5:

Create new Button(MultiSelectButton).Add the clicked() method under this Button.



Step 6:

Set the Property for Button Autodeclaration -->Yes and MultiSelect-->Yes.



Step 7:

Write the code for selecting multiple records.

void clicked()
{

    int             recordsCount;
    MultiSelectTable multiSelectTable1;
    super();

    recordsCount = MultiSelectTable_ds.recordsMarked().lastIndex();  // Total number of marked records.
  
  multiSelectTable1 = MultiSelectTable_ds.getFirst(1);

    while (multiSelectTable1)
    {
        info(multiSelectTable1.Name +" " +strFmt("%1",multiSelectTable1.Idnumber));
        multiSelectTable1 = MultiSelectTable_ds.getNext();
    }
}





Monday 15 September 2014

HOW TO DISPLAY GOOGLE WEBPAGE IN AX 2012

Now we are going to Discussing about display google webpage in ax 2012.I referred the blog axguruu.blogspot.in and got this ideas.

we have to follow some steps....

Step 1:

Create one form (GooglepageForm)

Step 2:

Under the Design node right click select Activex control.



Step 3:

After selecting this control we get one dialog box here select "Microsoft web browser" option.



Step 4:

After write the Init() method in form level.
public void init()
{
super();
Activex.Navigate("www.google.com");
}

Step 5:

We get the output,,,


Friday 12 September 2014

Import Records from CSV file for Particular TransferOrder in Inventory management module.

           Its similar to previous post but here we don't have any Menuitembutton and here we use main form(inventory module
  -->Transfers order).
              By using X++ code we generate New transfer order and Import items for that Transfor order from CSV file automatically.

Follow this Link you get more ideas and proper code,

Thursday 11 September 2014

Import records from CSV file to Ax for particular Transfer order by using MenuItemButton.


We have to follow some steps:-

Step 1:

Create a Table(ImportOption) with some fields.TransferId is one of the field which is mandatory.



Step 2:

Create a relation for TransferId with InventTransferTable.Set the Relation properties as follows..



Step 3:

Add Table as datasource into form(ImportOption).drag and drop the fields into design node.



Step 4:

Now add the form into Menuitem-->display node in AOT.

Step 5:

Create an Excel file with records which we need to import into ImportOption table.

Step 6:

Convert the excel file into CSV file(file-->save as-->Filename-->Book1-->Type-->CSV (comma delimited).



Step 7:

Create the MenuItemButton in the Action pane of the InventTransferOrder (or) CopyofinventTransferOrder form.



Step 8:

Now set the property menuItemName for that menuitembutton is ImportOption.



Step 9:

Under the menuitembutton write the clicked() method with following code,

void clicked()
{
Dialog dialog;
DialogField dialogFileName;
SysOperationProgress simpleProgress;
Filename filename;
FileIOPermission permission;
TextIO textIO;
ImportOption importOption;
InventTransferTable iinventTransferTable;


str itemname,transferid;

real qty;

str s11;
int i;
Container c1,c2;
CompanyInfo companyInfoLoc = CompanyInfo::find();
Container filterCriteria;
#File
#avifiles
super();

dialog = new Dialog("Importing Text File");
dialogFileName = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
filterCriteria = ['*.txt'];
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if (dialog.run())
filename = dialogFileName.value();
if(!filename)
{
info("Filename must be filled");

}
permission = new fileIOpermission(filename,#io_read);
permission.assert();
textIO = new TextIO(filename,#io_read);
textIO.inFieldDelimiter(',');///Change the Delimeter if it is , or ; etc
simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, 'Importing data',100);
if(textIO)
{
while(textIO.status() == IO_Status::Ok)
{
c1 = textIO.read();
s11 = conpeek(c1,3);
if(strlen(s11) > 1)
{
select importOption ;
importOption.Qty=conPeek(c1,1);
importOption.ItemName=conPeek(c1,2);
importOption.TransferIdentity=conPeek(c1,3);
importOption.insert();
i++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Lines imported: %1", i));
sleep(10);
}
}
}
}

Step 10:

This code used to import records from csv file.

If you want to modify records in csv files then right click the csv file-->open with -->notepad.Here change the records and save it.




Finally We get the output....

Tuesday 9 September 2014

Way to Solve the Transaction Tracking Error(TTS)


     We have some solutions for solving this type of error..




Solutions:

1.Check all code for form or class from where this error comes and count the ttsbegin and ttscommit there must be same like if u write 2 ttsbegin u must have to write 2 ttscommit.
2.One more step for solving this error,run this job it solves that error automatically.

static void ResetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    {
        info(strfmt("Level %1 aborted",appl.ttsLevel()));
        ttsAbort;
    }
}



Monday 8 September 2014

Developing a SSRS report using the Report Data Provider in Microsoft Dynamics AX 2012

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