Monday 26 May 2014

Restrict the Page header part of report to open on next page in ax 2009


Write the below code on header method . override executeSection() method.


public void executeSection()
{
if(element.page() == 1)
super();
}

Restrict User to enter only 10 digit numeric values in a string field on a Table.


public boolean validateField(FieldId _fieldIdToCheck)
{
boolean ret;
int q;
int ascii;
int i;
q= strLen(this.Phone);
ret = super(_fieldIdToCheck);
if(this.Phone)
{
for (i=1; i<=q; i++)
{
ascii = char2num(this.Phone, i);
if( ascii >= 48 && ascii <= 57)
ret = true;
else
{
ret = false;
error(‘Phone Number must be numeric only’);
break;
}
}
if(q!=10)
{
error(‘Phone Number must be of 10 digits’);
this.Phone = “”;
this.insert();
}
}
return ret;
}

Tuesday 25 March 2014

Browse File in ax 2012

static void Select_FileOpen(Args _args)
{
/*
This is the demonstration to select the file as a browser window
you can create fileOpen browser window
*/
Dialog dialog;
DialogField dialogField;
Filename filename;
;
dialog = new Dialog(“FileOpen”);
dialogfield = dialog.addField(extendedTypeStr(Filenameopen), “File Name”);
dialog.run();
if (dialog.run())
{
filename = (dialogfield.value());
}
info(filename);
}

Show (store/retrieve) Image on grid manually in ax 2012

Step 1 : Create a table and take Container type field  and extend it with Bitmap edt.
Image
Step 2: Create a Form  and drag & drop your field on that form Grid.
Capture2
Step 3: Now go to  window control > Methods > Override method > douseDblClick
Capture3
Now put the below code in these method
public int mouseDblClick(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)
{
int ret;
str imageFilePathName;
container imageContainer;
FilenameFilter filter = ['Image Files','*.bmp; *.jpg; *.gif; *.jpg'];
BinData bindata = new BinData();
str extension, path, nameOfFile;
ret = super(_x, _y, _button, _Ctrl, _Shift);
imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter,”,”,”,”);
if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
{
[path, nameOfFile, extension] = fileNameSplit(imageFilePathName);
if (extension == ‘.bmp’ ||
extension == ‘.jpg’ ||
extension == ‘.gif’ ||
extension == ‘.jpeg’)
{
binData.loadFile(imageFilePathName);
imageContainer = binData.getData();
ImageTable.Image = imageContainer; //Here ImageTable is your table name
}
}
ImageTable_ds.research(); // ImageTable_ds is your datasource name.
return ret;
}
Save all and open form ImageTable.
Capture4
Step 4 : Double Click on field and select image. you will see your form like these.
Capture5
You can do the same thing with button too.
I used Change for the same. write your code on Click method of button.
Thanks.

Monday 24 March 2014

How to convert Class File to XML file in Ax 2012

static void ClassToXml(Args _args)
{

    SysDictClass sysDictClass  = new SysDictClass(1023902);// used to find the class using classid
    TreeNode    treeNode = TreeNode::findNode(sysDictClass.path()); // to find the class in AOT
    TreeNode    childNode;
    int         counter=1;// used to count No of child nodes in the class
    str         nodename; // used to store the node name
    XmlTextWriter xmlDoc; // used to write xml file

    xmlDoc =XmlTextWriter::newFile("D:\Test.xml"); // creating xml file
    xmlDoc.writeStartDocument(); // writing xml docuemnt starting tag
    xmlDoc.writeStartElement("ClassInformation"); // root node
    xmlDoc.writeAttributeString("ClassName",sysDictClass.name()); // root node attirbutes

    if (treenode) // If  class is avilable
    {
        info(strfmt('number of methods in a classe: %1',treenode.aotchildnodecount()));
        childnode = treenode.aotfirstchild();
        while(counter <= treenode.aotchildnodecount())
        {
            xmlDoc.writeStartElement("MethodInformation");
            xmlDoc.writeAttributeString("MethodName",childNode.treeNodeName());
            xmlDoc.writeElementString("MethodContent",childNode.AOTgetSource());
            xmlDoc.writeEndElement();
            childnode = childnode.aotnextsibling(); // gets the next node
            counter++; // increments the counter by 1
        }
    }
    XMLDoc.writeEndElement(); // writes the End Tag
    xmlDoc.writeEndDocument(); // docuemnt ending.
    info("XML File is Created in D Drive");
}

Tuesday 18 March 2014

How to create Form using X++ in ax 2012.

static void createFormPk()
{
Args args;
Form form;
FormRun formRun;
FormBuildDesign fbDesign;
FormBuildDataSource fbDS;
FormBuildGridControl fbGrid;
FormBuildStringControl fbStr1;
FormBuildStringControl fbStr2;
FormBuildTabControl fbTab;
FormBuildTabPageControl fbTabPage1;
FormBuildTabPageControl fbTabPage2;
DictTable dictTable;
int idx, idx2, idx3;
FormControlType fctTabPage = FormControlType::TabPage;
FormControlType fctTab = FormControlType::Tab;
FormControlType fctGrid = FormControlType::Grid;
FormControlType fctString = FormControlType::String;
// Create the form header.
form = new Form();
// Add a data source to the form.
dictTable = new DictTable(tablenum(CustTable));
fbDS = form.addDataSource(dictTable.name());
fbDS.table(dictTable.id());
// Create the form design.
fbDesign = form.addDesign("Design");
fbDesign.caption("Customer information Pk");
// Add tab
fbTab = fbDesign.addControl(fctTab, "Overview");
// Add tab pages
fbTabPage1 = fbTab.addControl(fctTabPage, "Overview");
fbTabPage1.caption("Overview");

    fbTabPage2 = fbTab.addControl(fctTabPage,"General");
fbTabPage2.caption("General");
// Add grid onto tab 1 and data fields onto grid.
fbGrid = fbTabPage1.addControl(fctGrid,"Table Grid");
fbGrid.addDataField(fbDS.id(),
dictTable.fieldName2Id("AccountNum"));
fbGrid.addDataField(fbDS.id(),
dictTable.fieldName2Id("CustGroup"));
fbGrid.addDataField(fbDS.id(),
dictTable.fieldName2Id("Currency"));
// Add string fields to tab 2, and assign datasource
fbStr1 = fbTabPage2.addControl(fctString,"String 1");
fbStr1.dataSource(fbDS.id());
fbStr1.dataField(dictTable.fieldName2Id("AccountNum"));
fbStr2 = fbTabPage2.addControl(fctString,"String 2");
fbStr2.dataSource(fbDS.id());
fbStr2.dataField(dictTable.fieldName2Id("CustGroup"));
// Create the run-time form.
args = new Args();
args.object(form);
formRun = classfactory.formRunClass(args);
formRun.run();
formRun.detach();
}

How to Enable Disable Button Of list page using interaction class in ax 2012

Listpage interaction class: example

Listpage interaction class:( S3HrLeaveResquestListPageInteraction-interaction class,
S3HRLeaveRequestListPage-listpage name , DeleteCommandButton-button name(autodeclaration yes),
S3HRLeaveRequestListPage-listpage query, S3HRLeaveRequest_1-listpage table)


Create New Class & Write below code:=

public class S3HrLeaveResquestListPageInteraction extends SysListPageInteractionBase
{
    S3HRLeaveRequest S3HRLeaveRequest;
}


public void selectionChanged()
    {
S3HRLeaveRequest leaverequestCurrent = this.listPage().activeRecord(queryDataSourceStr(S3HRLeaveRequestListPage, S3HRLeaveRequest_1));
super();
 if(leaverequestCurrent.LeaveRequestApprovalStatus ==              S3HRLeaveRequestApproval::NotSubmitted)
        {
          this.listPage().actionPaneControlEnabled(formControlStr(S3HRLeaveRequestListPage,             DeleteCommandButton), true);
        }
        else
        {
            this.listPage().actionPaneControlEnabled(formControlStr(S3HRLeaveRequestListPage,             DeleteCommandButton), false);
        }
    }

Now extend this class to the form.