Skip to main content

Posts

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())

Get item from combobox using axapta code

Get item from combo box using axapta code. This function will return selected value of combo box control. I hope it can help you to avoid combo box troubleshooting. display str telNo() { telNo=CustTable::find(Table1.ParentOffice).Phone; Table1.TelNo = telNo; rec = ComboBox1.selectionChange(); officeName = ComboBox1.getText(ComboBox1.selectionChange()); parentOffice1 = Table1.ParentOffice; return CustTable::find(CustTable.AccountNum).Phone; }

Fill combo box using axapta x++ code

You can fill combo box two way first you can use lookup method using extended data type second if you are not using EDT then you can fill combo box by using following code. public void fillCombo() { CustTable custTable2; ComboBox1.clear(); SaleCalls.ParentOffice = "Abc"; custTable2 = CustTable::find(saleCalls.ParentOffice,false) rec = custTable2.RecId; while select * from Address where Address.AddrRecId == custTable2.RecId && Address.AddrTableId == custTable2.TableId { // ComboBox1.add(int2str(Address.RecId)); ComboBox1.add(Address.Name); } ComboBox1.selection(0); }

Method to Get Day difference using axapta

This method will show how to get day difference in ax. You need to declare variable as date type or you can use date extended data types same as you need to declare other type variable first to avoid error. Public void DayDiff() { //check for days Different tmpfromdt1 = date2str(tmpfromdt, 123, 2, 4, 2, 4, 4); tmpdiffdays = str2int(substr(tmpfromdt1,1,2)); mm = str2int(substr(DateFrom.valueStr(), 4, 2)); mm1 = str2int(substr(tmpfromdt1, 4, 2)); if(mm == mm1) { if(tmpdiffdays != 1) { tmpdiffdays1 = tmpdiffdays-1; } else { tmpdiffdays1 = 0; } } else { tmpdiffdays1 =0; } }

Procedure to Creating Budget Models in Axapta

To create a budget model: 1. From the Navigation pane, click GENERAL LEDGER→SETUP→BUDGET MODEL. 2. Click Ctrl+N to create a new record. 3. In the Budget Model field, type the name. 4. In the Name field, type a description of the budget model. 5. Select the Cash flow forecasts check box to apply cash flow forecasts to this model Attaching Sub models To attach a submodel to a budget model: 1. From the Navigation pane, click GENERAL LEDGER → SETUP → BUDGET MODEL. 2. On the Overview tab, click the budget model to which the submodel will be attached. 3. Click the Submodel tab. 4. Click Ctrl+N to create a new record, click the arrow, and then click the submodel to be attached to this model.

Dialog and get value from dialog box using Axapta

Below is a Code how  to add dialog and get value from dialog box in dynamics Axapta. This is very simple you just need to create one method which is overridden method is dialog. Dialog method used to initialized dialog box for your form or report but without using get from dialog method you can not get value of dialog control. So both method is important dialog and getfromdialog. public Object dialog(Object _dialog) { DialogRunbase dialog = _dialog; DialogGroup dateGroup; ; dateGroup = dialog.addGroup(""); dateGroup.frameType(1); dateGroup.columns(2); fromdate = LedgerPeriod::findOpeningDate(systemdateget()); toDate= systemdateget(); dialog.addGroup("@SYS4083",dateGroup); dialogFromDate = dialog.addFieldValue(typeid(FromDate),fromDate,'',"@SYS67"); dialog.addGroup("@SYS8828",dateGroup) ; dialogToDate = dialog.addFieldValue(typeid(ToDate),toDate,'',"@SYS67"); dialog.addGroup