Thursday, January 30, 2014

How To Insert The Data Into Table Using CSV File.

Hi This is post tells the how to upload the records into a Database Table using CSV file and Using TextIo.

static void ExampleInsertDataUsingFile(Args _args)
{
Dialog dlg;
DialogField dlf;
Filename fileName;
FilenameOpen fileNameLocation;
container con;
CommaIo commaIo;
FileIOPermission permission;
int iId;
str sName;
tblFileUpload TblFileUpload;

;

dlg=new Dialog();
dlf=dlg.addField(“FilenameOpen”,”fileNameLocation”);
if(dlg.run())
{
fileName =dlf.value();
permission=new FileIOPermission(fileName,’r');
permission.assert();
commaIo=new CommaIo(fileName,’r');
commaIo.inFieldDelimiter(‘,’);
if(commaIo)
{
while(commaIo.status()==IO_Status::Ok)
{

con=commaIo.read();
if(con !=conNull())
{

TblFileUpload.Id=conPeek(con,1);
TblFileUpload.Name=conPeek(con,2);
TblFileUpload.insert();
info(“Inserted Successfully…”);
while select TblFileUpload
{
print TblFileUpload.Id;
print TblFileUpload.Name;

}

// iId=conPeek(con,1);
// sName=conPeek(con,2);
//info(sName);
}
}
}
pause;

}

}

Insert Multiple Records using X++

static void ExampleInsertMultipleRecordsWithOneShot(Args _args)
{
tblEmpTable EmpTable;

RecordInsertList Ril;
int i=6;
;

Ril=new RecordInsertList(tableNum(tblEmpTable));
for(i=6;i<=12;i++) { EmpTable.EmpId=i; EmpTable.EmpName="Abcd"; Ril.add(EmpTable); } Ril.insertDatabase(); }

Delete The Record Using X++

static void ExampleForDelete(Args _args)
{
tblParent Parent;
DialogButton Db;
;
Db= Box::yesNo(“Do You Want to Delete the Record…?”,DialogButton::No);
if(Db==DialogButton::Yes)
{
ttsBegin;

delete_from Parent where Parent.deptNo==10;
//{
//Parent.Delete();

// }
ttsCommit;

while select Parent
{
//info(“Dept No : “,strFmt(Parent.deptNo) ” Dept Name : ” +Parent.deptName);
print Parent.deptNo;
print Parent.deptName;

}pause;
}
else
{
while select Parent
{
//info(“Dept No : “,strFmt(Parent.deptNo) ” Dept Name : ” +Parent.deptName);
print Parent.deptNo;
print Parent.deptName;

}pause;
}
}

Update The Record Using X++

static void ExampleUpdateTable(Args _args)
{
tblParent ParentTable;
DialogButton Db;
;
ttsBegin;
while select forUpdate ParentTable where ParentTable.deptNo==10
{
ParentTable.deptName = “software”;
ParentTable.update();
}
ttsCommit;
}

Insert The Record Using X++

static void ExampleOfInsertionUsingDialogbuttion(Args _args)
{
tblParent ParentTable;
DialogButton Db;

;

Db=Box::yesNo(“ARK”,DialogButton::Yes);
if(Db==DialogButton::Yes)
{
ParentTable.deptName=”SoftWare”;
ParentTable.deptNo=10;
try{
ParentTable.insert();
Box::info(“Insert Successfully…”);
}
catch(Exception::Info)
{
info(“Caught Catch Exception”);
}
}
else
{
info(“Notinserted.”);
}

}

Monday, January 20, 2014

Insert and DoInsert

Step 1:- create the Table(InsertOperations) with fields(AcNo,Name,City,PhoneNo,EmailId)
Step 2:- Take One new job and insert the data into created table through X++ coding

Static void InsertOperatations(Args _args)
{
              InsertOperatations insertoperatations;
              Insertoperatations.AcNo=”1”;
              Insertoperatations.Name=”A”;
              Insertoperatations.City =”Hyd”;
              Insertoperatations.PhoneNo=”1234567890”;
              Insertoperatations.Email=”a@gmail.com”;
              Insertoperatations.insert();
  }

Before Insert open the table.
Step 3:- Now we override the method insert. Go to the table-> expand the + button-> find the methods node -> Rightclick on methods node ->override-> insert writhe the following code. This.city=”HYD”; Super(); Now the above job you’ve to change the data as well as different city also. Suppose you are giving any city but It insert the data only HYD. Bcoz you are override the method is Insert. Imp:- before super only we’ve to give the default value of country.

Step 4:- Now we are try to insert 2nd record And open the table and check the Data. DOINSERT

Step 5:- use the command do Insert. Just replace the instead of insert to doinsert. Static void InsertOperatations(Args _args) { InsertOperatations insertoperatations; ; Insertoperatations.AcNo=”1”; Insertoperatations.Name=”A”; Insertoperatations.City =”Hyd”; Insertoperatations.PhoneNo=”1234567890”; Insertoperatations.Email=”a@gmail.com”; Insertoperatations.doinsert(); } Check overridden insert method also Now open the table and check the data. Bcoz the doinsert method bypass the insert method. It is what ever we want give the data it bypass the insertmethod and push the data into Table.

Video Tutorial Of this Post

Wednesday, January 8, 2014

Dialog In Ax-2012

static void DialogUsingAddition(Args _args)
{
    Dialog dlg1;
    Dialog dlg2;
    DialogField dlf1;
    DialogField dlf2;
    int a;
    int b;
    int c;
    AirthematicOperatations aithematic;
    ;
    dlg1=new Dialog();
    dlg2=new Dialog();
    dlf1=dlg1.addField("EnterFirstNumber","Please Enter First Number.");
    dlf2=dlg2.addField("EnterSecondNumber","Please Enter Second Number");
    if(dlg1.run())
    {
        a=dlf1.value();
       // info(strFmt("%1",a));
       
    }
    if(dlg2.run())
    {
        b=dlf2.value();
    }
   // c=a+b;
    //info(strFmt("The Addition is:-  %1 ", c));
   
    // Passing these values to Class
   
   //aithematic=new AirthematicOperatations();
   //aithematic.Add(a,b);
   
    if(a < b)
    {
        c=a*b;
        info(strFmt(" A > B Is:- %1 ",c));
    }
    else if(a>b)
    {
        c=a+b;
        info(strFmt("A + B Is :- %1 ", c));
    }
    else if(a == b)
    {
        info(strFmt("Both Values or Equal.."));
    }
}

CrosssCompany In DAX 2012

static void CrossCompanyEx(Args _args)
{
   TblCrossCompany tbl;
    container con;
   
    ;
   // select crossCompany:conCompanies
    //* from ct
   // changeCompany("cec")

   // con=["cec"];
    while select   crossCompany * from tbl //where tbl.Id=="101"
    {
        print tbl.Id;
        print tbl.Name;


    }
    pause;



}