Skip to main content

Posts

Showing posts from July, 2010

Display data of particular division and circles and filter data separated by comma

Display data of particular division and circles and filter data separated by comma public void UserRigths() { currentUserId = curUserId(); select * from sysCompanyUserInfo where sysCompanyUserInfo.UserId == currentUserID; if(sysCompanyUserInfo) { if(sysCompanyUserInfo.EmplId != "") { while select * from EmplTable2 where EmplTable2.EmplId == sysCompanyUserInfo.EmplId { d1 = System.Convert::ToString(EmplTable2.Dimension[2]); } if(d1 != "") { while select * from _OrganizationChart2_1 where _OrganizationChart2_1.WareHouseCode == d1 { _Office_type = _OrganizationChart2_1.Office_type; } } if (d1 != "") { if ((enum2str(_Office_type) == "Sachivalaya") || (enum2str(_Office_type) == "CE") || (enum2str(_Office_type) == "Circle") ) { while select * from _OrganizationChart2_2 where _OrganizationChart2_2.ParentWareHouseCode == d1 { OfficeName += _OrganizationC

Delete_from command to delete from table in axapta

As with the insert_recordset and update_recordset operators, there is also an option for deleting a chunk of records. This operator is called delete_from and is used as the next example shows: static void Delete_FromExample(Args _args) { CarTable carTable; ; delete_from carTable where carTable.Mileage == 0; }

Get current financial year from date and To date in axapta

public str getFinyear_To() { yy= 0; mm =0; mm3=""; DtFrm = todt; strdtfrm = date2str(todt, 123, 2, 4, 2, 4, 4); mm = str2int(substr(strdtfrm, 4, 2)); yy = str2int(substr(strdtfrm, 7, 4)); yy5 = str2int(substr(strdtfrm, 7, 4)); mm3 = substr(strdtfrm, 4, 2); if (mm <= 4) { yy--; } finYrTo = int2str(yy) + '-';  yy++; finYrTo += substr(int2str(yy),3,2); return finYrTo; }  public str getFinyear_From() { ; DtFrm = frmdt;  strdtfrm = date2str(dtfrm, 123, 2, 4, 2, 4, 4); mm = str2int(substr(strdtfrm, 4, 2)); yy = str2int(substr(strdtfrm, 7, 4)); mm2= substr(strdtfrm, 4, 2); yy4 = str2int(substr(strdtfrm, 7, 4));  if (mm <= 3) { yy--; }  finYrFrom = int2str(yy) + '-';  yy++; finYrFrom += substr(int2str(yy),3,2); return finYrFrom; } 

Get current financial year in axapta

display str CurFinYr() { DtFrm = frmdt; strdtfrm = date2str(dtfrm, 123, 2, 4, 2, 4, 4); yy = str2int(substr(strdtfrm, 7, 4)); Fyy = substr(int2str(yy),3,2); DtTo = toDt; strdtto = date2str(DtTo, 123, 2, 4, 2, 4, 4); yy = str2int(substr(strdtto, 7, 4)); Tyy = substr(int2str(yy),3,2); CurFinYr=Fyy+" - "+Tyy; return CurFinYr; }

Get previous financial year in axapta

By using this method you can Get previous financial year in axapta. If you are using from date and to date in ax and these date belongs to current financial year but your requirement is to get 1 year back financial year then you can use this method. Display str PrevFinYr() { str f,t; DtFrm = frmdt; strdtfrm = date2str(dtfrm, 123, 2, 4, 2, 4, 4); yy = str2int(substr(strdtfrm, 7, 4)); Fyy = substr(int2str(yy),3,2); DtTo = toDt; strdtto = date2str(DtTo, 123, 2, 4, 2, 4, 4); yy = str2int(substr(strdtto, 7, 4)); Tyy = substr(int2str(yy),3,2); if ((str2int(fyy)-1)<10) {  f="0"+int2str(str2int(fyy)-1);  }  else  { t=int2str(str2int(fyy)-1);  }  if ((str2int(tyy)-1)<10) { t="0"+int2str(str2int(tyy)-1); } else {  t=int2str(str2int(tyy)-1); }  PrevFinYr=f +" - "+ t; return PrevFinYr; }

Binding user to particular office in axapta application

This is simple filter code for Binding  user to particular office in axapta application. Like current user is adam and you want to show him only one employee date then you can use filter methodology this way. public void filter1() { UserId currentUserId; SysCompanyUserInfo sysCompanyUserInfo; _ServiceDetails2 _ServiceDetails2; EmplTable emplTable; InventLocationId inventLoc; Date LastDate; RecId RecId; currentUserId = curUserId(); select * from sysCompanyUserInfo where sysCompanyUserInfo.UserId == currentUserID; if(sysCompanyUserInfo) { if(sysCompanyUserInfo.EmplId != "") { select * from emplTable where emplTable.EmplId == sysCompanyUserInfo.EmplId; if(emplTable) { if(emplTable.EmplId != "") { while select * from _ServiceDetails2 where _ServiceDetails2.EmplId == emplTable.EmplId { if(LastDate == any2date(0)) { LastDate = _ServiceDetails2.DateTo; RecId = _ServiceDetails2.RecId; } else { if(LastDate < _ServiceDetails2.DateTo) { L

Insert and delete item from container in Axapta

This is a sample of code how to Insert and delete item from container in Axapta. This code you can apply in form or report for your purpose. static void Datatypes_container_functions(Args _args) { container con; ; // conins - Insert values to the container con = conins(con, 1, "Toyota"); con = conins(con, 2, 20); con = conins(con, 3, 2200.20); con = conins(con, 4, "BMW"); con = conins(con, 5, 12); con = conins(con, 6, 3210.44); // condel - Delete the third and the fourth element // from the container con = condel(con, 3, 2); // conpeek - Read values from the container info(conpeek(con,1)); info(conpeek(con,2)); info(conpeek(con,3)); info(conpeek(con,4)); // connull - Reset the container con = connull(); // conlen - Get the length of the container info(strfmt("Length: %1",conlen(con))); }

Fetch Method to make Trial balance quickly

This is simple Fetch Method to make Trial balance quickly. Some times standard trial balance does not match due to wrong customization of application so there may be data problem in ledger balance table then you can make trial balance by using LedgerTrans table. Performance of report will be slow but it can give accurate result. public boolean fetch() { Query q = new Query(); QueryBuildDataSource qbds; ; q= this.query(); qbds = q.dataSourceTable(tablenum(LedgerTrans)); qbds.addSortField(fieldnum(LedgerTrans,AccountNum)); rangeTransDate =qbds.findRange(fieldnum(LedgerTrans,TransDate)); purpose1 = qbds.findRange(FieldId2Ext(FieldNum(LedgerTrans, Dimension),3)); if(!rangeTransDate.value()) { rangeTransDate.value(queryRange(dateMin,dateMax)); fromdate= dateMin; todate =dateMax; } else { value=rangeTransDate.value(); if(strfind(value,".",1,11) != 0) { mindate1 =strdel(value,strfind(value,".",1,11),strle

strscan function to scan string characters in axapta

This is a sample of code how to use of strscan function in axapta to scan string from string. void ArrayAccount() { //s = ""; // len = strlen( _s ); // pos = strfind( _s, _delimeter, len, -len ); // s = strdel( _s, 0, pos ); cntAc =1; name = System.Convert::ToString(BHead); Accountname[cntAc] = LedgerTable::find(name).AccountName; len = strlen(name); for (i = 0; i<=len;i++) { pos = strscan( name, ".", strlen( name ), 0 - strlen( name ) ); fName = strdel( name, pos, strlen( name ) - pos + 1 ); lastName = strdel( name, 1, pos ); if (FName != "") { name = fName; cntAc++; Accountname[cntAc] = LedgerTable::find(name).AccountName; } } }

Add date range value from dialog to report through code in Axapta

This is a sample code to Add date range value from dialog to report through code in Axapta. This code is to use in report of Ax. Getfromdialog and dialog is overridden method in Ax report. public boolean getFromDialog() { ; cmbOfficeCode = dialogOffice.value(); // cmbProjId = dialogProjId.value(); DateType = dialogDateType.value(); fromdate = dialogfromdate.value(); todate = dialogtodate.value(); return true; } public Object dialog(Object _dialog) { DialogRunbase dialog = _dialog; ; cmbOfficeCode = InventId; cmbProjId = ProjId1; dialogOffice = dialog.addFieldValue(typeid(InventLocationId), cmbOfficeCode); //dialogProjId = dialog.addFieldValue(typeid(ProjId), cmbProjId); dialogDateType = dialog.addFieldValue(typeid(Irrigation_Date),"Select Date", "Select Date"); dialogFromDate = dialog.addFieldValue(typeid(FromDate), fromDate); dialogToDate = dialog.addFieldValue(typeid(ToDate), toDate); return dialo

Create Organization hierarchy Chart in axapta

These are method to create organization hierarchy chart in Axapta public class FormRun extends ObjectRun { CCFormTreeDatasource treeDatasource; } void InsertinTemp() { TmpOrganizationChart2 TmpOrganizationChart2_1; _OrganizationChart2 _OrganizationChart2_1; ; /*hile select _OrganizationChart2_1 { while select forupdate TmpOrganizationChart2_1 where TmpOrganizationChart2_1.WareHouseCode==_OrganizationChart2_1.WareHouseCode { TmpOrganizationChart2_1.delete(); } }*/ Delete_from TmpOrganizationChart2_1; While select _OrganizationChart2_1 { TmpOrganizationChart2_1.WareHouseCode=_OrganizationChart2_1.WareHouseCode; TmpOrganizationChart2_1.ParentWareHouseCode=_OrganizationChart2_1.ParentWareHouseCode; TmpOrganizationChart2_1.Office_type=_OrganizationChart2_1.Office_type; TmpOrganizationChart2_1.Name=InventLocation::find(_OrganizationChart2_1.WareHouseCode).Name; TmpOrganizationChart2_1.insert(); } } public void

Load data to chart in axapta

If you want to Load data to show as a  chart in axapta then you need to drag chart control to form group or tab then you can store data in to tables. You can use while loop to take data in looping and at the time of loop execution you can call data to graph. This is a simple method which you can call on init method of form to show data initially. void createGraph() { //SalesLine salesline; // graphics graphics,graphics1; int i,k; str month; // date createddate; #macrolib.ChartFx ; graphics1 = Graphics::newGraphicsTitlesLayout(ChartX, 100, 200,'Title', 'X', 'Y', 'z',1 ,1, 1, 1); graphics1.create(); graphics1.parmTitle(""); graphics1.parmTitleXAxis('Year'); graphics1.parmTitleYAxis('Weight(Kg.)'); ChartX.Chart3D(true); ChartX.toolBar(true); //graphics.Gallery(9); ChartX.Gallery(6); ChartX.DataEditor(true); ChartX.grid(1); ChartX.BackColor(16777215); ChartX.ToolBa

Use temporary variable to distinct or group by element to fetch record in Axapta

Fetch method is override method of report in axapta. You can Use temporary variable to distinct or group by element to fetch record in Axapta . By this example you can get only hints or idea to use in your report. public boolean fetch() { Query q = new Query(); QueryBuildDataSource qbds; ; q= this.query(); qbds = q.dataSourceTable(tablenum(LedgerTrans)); // qbds = q.addDataSource() qbds.addSortField(fieldnum(LedgerTrans,AccountNum)); rangeTransDate =qbds.findRange(fieldnum(LedgerTrans,TransDate)); purpose1 = qbds.findRange(FieldId2Ext(FieldNum(LedgerTrans, Dimension),3)); if(!rangeTransDate.value()) { rangeTransDate.value(queryRange(dateMin,dateMax)); fromdate= dateMin; todate =dateMax; } else { value=rangeTransDate.value(); if(strfind(value,".",1,11) != 0) { mindate1 =strdel(value,strfind(value,".",1,11),strlen(value)); maxdate1 =strDel(value,strfind(value,".",1,11)+1,-(strfind(val

Use multiple table link through code in Axapta report

public boolean fetch() { str 50 tmpregno; QueryBuildDataSource qbds,qbds1,qbds2; QueryBuildRange queryBuildRange; QueryBuildRange rangeTransDate; QueryRun qr1; QueryBuildLink QueryBuildLink_1; query q = new Query(); query q1 = new Query(); ; // frmdt = str2date("01/05/2010",123); // todt = str2date("30/05/2010",123); q = this.query(); q1 = this.query(); qbds2 = q.addDataSource(tablenum(_Registration)); qbds1 = qbds2.addDataSource(tablenum(_RegistrationDetails)); qbds = qbds1.addDataSource(tablenum(_Register4)); qbds.joinMode(JoinMode::InnerJoin); QueryBuildLink_1 = qbds.addLink(fieldNum(_RegistrationDetails, _RegistrationNo), fieldNum(_Register4, RegistrationNo)); qbds.relations(true); queryBuildRange = qbds.addRange(fieldNum(_Register4, ProcessDate)); rangeTransDate = qbds.findRange(fieldnum(_Register4,ProcessDate)); /* if(!rangeTransDate.value()) { rangeTransDate.value(queryRange(dateMin,dateMax)); if (dateMin ==str2date(

Add multiple range and multiple table lookup

This is a sample code to Add multiple range and multiple table lookup in Axapta. public void lookup() { SysTableLookup tableLookup; QueryBuildRange rangeTransDate; QueryBuildRange vlgCode,ItemId,DistCode,talCode; QueryBuildRange CropId; QueryRun queryRun; QueryBuildDataSource qbds,qbds1,qbr,qbr1,qbr2; Query q = new Query(); Query q1 = new Query(); QueryBuildLink QueryBuildLink1,QueryBuildLink2; _TmpLookup _TmpLookup1; InventTable InventTable_1; boolean flg; ; tableLookup = SysTableLookup::newParameters(tableNum(_TableDetails),this); qbr = q.addDataSource(tableNum(_TableDetails)); qbr2=qbr.addDataSource(tablenum(_Inspection1)); qbr2.joinMode(Joinmode::NoExistsJoin); QueryBuildLink2 = qbr2.addLink(fieldnum(_TableDetails, _TableNo),fieldnum(_Inspection1,TableNo)); // qbr2.addRange(fieldnum(_TableDetails,_TableNo)).value(queryNotValue(SysQuery::valueEmptyString())); qbr2.relations(true); if(tmpfilter.DistrictCode != &quo

check existence of table in axapta

This is sample code to  check existence of table in  axapta. This is just an example to check whether that table exist in AOT (Application object tree) or not. If table exist then it will return true otherwise it will show error the table is already exists. public boolean modified() { boolean ret; ret = super(); flag = false; value= Controlname.valueStr(); flag = TableName::exist(value); if (flag == true) { info("Already Exists"); } return ret; }

Call other form on button clicked event in MSD axapta

This is sample code to Call other form on button clicked event in axapta. Just write code on button clicked event. That form will be run on event. You can call this code on button click method . There are two way to do this one is that you care menu item and drag that menu item in form other is you need to write code like below. void clicked() { super(); new MenuFunction(menuitemdisplaystr(FormMenuitemname), MenuItemType::Display).run(); }

The most commonly used classes in the query object model

• Query: Contains the definition of the query. Can consist of one data source or several data sources if they are related. • QueryRun: Class used to execute the query and loop through the result. • QueryBuildDataSource: Links to one data source in the query. Can be linked to another QueryBuildDataSource object to join linked data sources. • QueryBuildRange: Enables the end user to limit the result by adding a value in the specified query range. • QueryBuildFieldList: List of all the fields in data source. One QueryBuildFieldList object for each QueryBuildDataSource. By default the property Dynamic is set to true so that all fields are returned. • QueryBuildLink: Links two data sources in a join. Is set on the child data source.

Struct

Struct A struct can be viewed upon as a class with no method, only attributes. It can store several values of different data types, but one struct can only hold one set of values. static void Collection_Struct(Args _args) { // Create a struct with two fields struct myCar = new struct ("int ModelYear; str Carbrand"); int i; ; // Set values to the fields myCar.value("ModelYear", 2000); myCar.value("Carbrand", "BMW"); // Add a new field and give it a value myCar.add("Model", "316"); // Loop through the fields of the struct for (i=1; i<=myCar.fields(); i++) { info(strfmt("FieldType: %1, FieldName: %2, Value: %3", myCar.fieldType(i), myCar.fieldName(i), myCar.value(myCar.fieldName(i)))); } }

Map in Microsoft Dynamics Axapta

The map is used to index a value using a key value. Both the key and the value can be of any types specified in the Types enum. static void Collection_Map(Args _args) { // Create a new map with a key and value type Map cars = new Map(Types::Integer, Types::String); MapEnumerator mapE; ; // Insert values to the map cars.insert (1, "Volvo"); cars.insert (2, "BMW"); cars.insert (3, "Chrysler"); // Display the content of the map info (cars.toString()); // Get the enumerator to loop // through the elements of the map mapE = cars.getEnumerator(); while (mapE.moveNext()) { info(strfmt("Car %1: %2", mapE.currentKey(), mapE.currentValue())); } }

Sending Report through email in axapta

This is the sample code for Sending Report through email in axapta. This cod you can use in any version of Ax (3.0,4.0,2009,2012 etc) void reportSendMail(PrintJobSettings p1) { //SysINetMail m = new SysINetMail(); // Mo : Commented out old AX code System.Net.Mail.MailMessage mailMessage; System.Net.Mail.Attachment attachment; System.Net.Mail.AttachmentCollection attachementCollection; System.Net.Mail.SmtpClient myMail; System.Net.Mail.MailAddress mailFrom; System.Net.Mail.MailAddress mailTo; str userMailAddress; str receiverMailAddress; str mailBody; str smtpServer; fileNameOpen fileNameForEmail; str mail; FileIOPermission perm; userinfo userInfo; //end Declaration str fileName = 'axaptareport'; ; if (p1.format() == PrintFormat::ASCII) fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999)+'TXT'; // Mo : NL //fileName = fileName + '.txt'; // Mo Commented this line else if (p

Create and delete folder using axapta x++ code

This is sample of code to Create and delete folder using axapta in x++ code. This code you can check in job or any button click . First you need to test this code before applying to production server. public void CreateFolder() { boolean FlagFolderExist,FlagFileExist; FlagFolderExist = WINAPI::folderExists("C:\\roll\\"+ cate1); if(FlagFolderExist == false) { WINAPI::createDirectoryPath("C:\\roll\\"+rollcate1); } FlagFileExist = WINAPI::fileExists("C:\\roll\\" + rollcate1 + "\\" + Tmpemplname); if(FlagFileExist == true) { WINAPI::deleteFile("C:\\roll\\" + rollcate1 + "\\" + Tmpemplname); } }

Add range, Sort field, datasource in axapta using code in report

This is sample code to Add range, Sort field, datasource in axapta using code in report. This code you can apply in fetch method in Report. This code is related to Axapta report. QueryBuildRange fromdt,todt; str value; Query q = new Query(); Query q1 = new Query(); QueryBuildDataSource qbds,qbds1; QueryBuildRange startTransDate; QueryBuildRange endTransDate; QueryRun qr1; Add range, Sort field, datasource in axapta using code in report q = this.query(); q1=this.query(); qbds = q.dataSourceTable(tablenum(EmplTable)); // dateMin = str2date(mindate1,123); qbds1=q1.dataSourceTable(tablenum(_PMaster)); qbds1.addSortField(fieldnum(_PMaster,PCategory)); fromdt =qbds1.findRange(fieldnum(_PMaster,Date_From)); todt=qbds1.findRange(fieldnum(_PMaster,Date_To)); mindate1=fromdt.value(); maxdate1=todt.value(); fromDate=str2date(mindate1,123); toDate=str2date(maxdate1,123);

Increase Serial number in axapta through code

This is sample code to Increase Serial number in axapta through code. There are two way to set serial number one is number sequence other is maintain sequence number by code. This is way to increase serial number if you do not want to use number sequence . display str privateMethod() { int ss=0; str SrNo; ActualWorkDet actualWorkDet1; Query query; QueryBuildDataSource queryBuildDataSource; QueryBuildRange queryBuildRange; QueryRun queryRun; int total; ; //itemid="CN-01"; //itemid=Itemhead.itemid(); itemid=ActualWorkHead.ProdId; if (itemid != "") { query = new Query(); queryBuildDataSource =query.addDataSource(tableNum(ActualWorkDet)); //queryBuildDataSource.addSelectionField(fieldNum(CopyOfItemRoutesDet,SrNo),SelectionField::count); queryBuildDataSource.addSelectionField(fieldnum(ActualWorkDet,SrNo), SelectionField::Max); //queryBuildDataSource.orderMode(OrderMode::GroupBy); queryBuildRange =queryB

Example of Fetch Method in Axapta

This is sample code for fetch method for Ax reports. In this code you can get idea that how to add or find range on report ,How to add data source for table in report,how to user queryrun on report. How to send data to table to show on report and how to execute section on report. public boolean fetch() { boolean ret; // ret = super(); _Test _Test1; QueryBuildDataSource qbds; QueryBuildRange TestId2; Query q = new Query(); int i; str stri; str rowid; TestId testid1,oldtestid; ; q = this.query(); /* qbds = q.dataSourceTable(tablenum(_Question)); qbds.addRange(fieldnum(_Question,TestId)); TestId2=qbds.findRange(fieldnum(_Question,TestId)); queryRun = new queryRun(q);*/ qbds = q.dataSourceTable(tablenum(_Test)); qbds.addRange(fieldnum(_Test,TestId)); TestId2=qbds.findRange(fieldnum(_Test,TestId)); queryRun = new queryRun(q); oldtestid=""; while (queryRun.next()) { // _question = queryRun.get(tablenum(

add run time control in axapta

This is a sample code to add run time control in axapta form. This is not 100% accurate code but this can help you to create run time control. There is no guarantee that  run time control will work perfectly in Ax I tried it but did not get much success on this but what success I get I shared here. public void init() { int i; int a; int d; int j=0; str lable; DictTable dictTable; TableId tableID; //TestId testId1; FormStringControl fStringTestID; str GetParm; str ParmCaller; ///// FormBParams formBParams; Array items; object formRunCaller; //FormRun formRun; //Args args; ; // if( element.args() ) // { // get string parameter // testId1= this.TestID() ; formRunCaller = element.args().caller(); if(formRunCaller) { testId1=formRunCaller.MethodA(); } // } //ssss /*if(element.args()) { testId1=element.args().parm(); } if(element.args().caller()) {//element.args().record().update

Runtime form controls using Axapta and save data

This is sample code for Runtime form controls using MSD Axapta and save data to table public void GenerateControl() { int i; int a; int d; str lable; DictTable dictTable; TableId tableID; ; i = 1; d=1; a=0; lable = ""; formTabControl = this.form().addControl(FormControlType::Tab,"MainTab"); formTabControl.heightMode(1); formTabControl.widthMode(1); formTabPageControl = formTabControl.addControl(FormControlType::TabPage,"MainTabPage"); formTabPageControl.caption("Test"); this.controlMethodOverload(true); formGroupControl = formTabPageControl.addControl(FormControlType::Group, "MyGroup"); formGroupControl.caption("Test"); while select * from _Question order by RecId { a = 1; while select * from answer where answer.GroupId == _Question.GroupId { if(_Question.ControlId == QuestionControlInputType::CheckBox) { formCheckBoxControl = formGroupCont

Fetch Method in Ax Reports of Microsoft Dynamics axapta x++

This is example of Fetch Method in Ax Reports of Microsoft Dynamics axapta x++ language. By this example you can get Idea that how to declare variables to use querybuilddatasource at run time. You can see how to add query range in querybuilddatasource  object. Here report programmable section used to execute. public boolean fetch() { QueryBuildRange rangeStatus; Query q = new Query(); QueryBuildDataSource qbds; ; q = this.query(); qbds = q.dataSourceTable(tablenum(Table1)); if (groupByClosed1 == 1) { qbds.addRange(fieldnum(Table1,Closed)).value(enum2Value(groupByClosed1)); } if (groupByImplemented1 == 1) { qbds.addRange(fieldnum(Table1,Implemented)).value(enum2Value(groupByImplemented1)); } if (groupByPending1 == 1) { groupByPending1 = 0; qbds.addRange(fieldnum(Table1,Closed)).value(enum2Value(groupByPending1)); } qbds.addSortField(fieldnum(Table1,TicketNo)); queryRun = new QueryRun(q); while(queryRun.next())