Sie sind auf Seite 1von 12

DAX Samples Validate Field Example: Public Boolean validateField(fielded _fieldIdToCheck) { Boolean ret; Ret = super(_fieldIdToCheck); If(_fieldIdToCheck == fieldNum(kkk_CustTable,

CreditLimit) { If(this.CreditLimit > 2000.00) { Ret = ret && checkFailed(Credit limit cannot be greater than 2000); } } Return ret; } Container Example: Container con = [1000, xyz, 40, 500.00]; Container rcon; Int I; ; Info(int2str(conlen(con)); Info(conpeek(con,3)); Conview(con); For(I =1; i<=conlen(con);i++) { Info(conpeek(con,i)); } Rcon = condel(con,1,2); Conview(rcon); Con = connull(); Conview(con); Info(strfmt(xyz is found at %1,confind(con,xyz))); Functions : Conpoke - replace an element Conins insert an element Conlen find length Conpeek will get the value

Condel deletes set of elements in container and return new container Confind will find an element in container Connull null the container Conview show all the elements in container

Macros: Declaring: #define.NoOfStudents(40) Using: #NoOfStudents Passing Values: Static void job1(Args _args) { Int c; #localmacro.sum C = %1 + %2; #endmacro ; #sum(10,20); Info(int2str(c)); } Passing values from one form to another: Public void init() { KKK_CustTable k; ; If(!element.args().caller()) { Throw error(Form cannot be opened directly); } K = element.args().record(); Super(); StringEdit.text(k.AccountNum + + k.Name); }

Pass the element from caller to the called. The above is code for called form. Opening a form from another form using X++ code: Void clicked() { Args args; FormRun formRun; ; Super(); Args = new Args(formstr(KKK_SecondForm)); formRun = ClassFactory.formRunClass(args); args.caller(element); args.record(KKK_CustTable); args.parm(college.text()); formRun.init(); formRun.run(); formRun.wait(); } Getting parm values in child form: Str College; ; College = element.args().parm(); Following are used to display hour glass: startLengthyOperation() endLengthyOperation() Animate Controls on Form: Add animate control to form, Public void init() { #AviFiles Super(); Animate.animateFile(#AviSearch); Animate.autoPlay(true);

} Progress Bar: Static void KKK_ProgressBars(Args _args) { SysOperationProgress progress = new SysOperationProgress(); #AviFiles Int I; ; Progress.setAnimation(#aviPrint); Progress.setTotal(100000); Progress.setCaption(Progress Bar Example); For(i=1;i<=100000;i++) { Progress.incCount(); Progress.setText(strfmt(The value of I is %1,i)); } } Joins: Inner Join Outer Join Exists Join NotExistsJoin

Select if key fiels Equal, From parent and child Select all, From parent and child Select if exists, From parent only Select if child doesnt have matching records, Only from parent

Box Class If(Box::YesNo(Do you want to delete records, DialogButton::No, Box Example, Bottom text of box) == DialogButton::Yes) { } Dialogs: Dialog d = new Dialog(My Dialog); DialogField dfName, dfAge; ; dfName = d.addField(Types::String, Name, Name of Customer); dfAge = d.addField(Types::Integer, Age, Age of Customer); if(d.run()) {

Info(dfName.value()); Info(dfAge.value()); } Else { Throw error(User Cancelled); } RunBase Framework: Tutorial_RunBase

Queries: Using AOT Queries: Query q = new Query(querystr(KKK_CustTable)); QueryRun qr; KKK_CustTable k; ; Qr = new QueryRun(q); If(qr.prompt()) { While(qr.next()) { K = qr.getNo(1); // Use qr.get(tablenum(KKK_CustTable)); Info(k.Name + , + k.AccountNum); } } Dynamic Queries (X++ Queries): Query q = new Query(); QueryBuildDataSource qbds; QueryBuildRange qbrAccNo, qbrName; QueryRun qr; KKK_CustTable k;

; Qbds = q.addDataSource(tablenum(KKK_CustTable)); qbrAccNo = qbds.addRange(fieldnum(KKK_CustTable, AccountNum)); qbrAccNo.status(1); qbrAccNo.value(100..200); qbrName = qbds.addRange(fieldnum(KKK_CustTable, Name)); qr = new QueryRun(q); if(qr.prompt()) { While(qr.next()) { K = qr.getNo(1); Info(k.AccountNum); } }

Creating Filtrations on Form: QueryBuildRange executeQuery on data source example: public class FormRun extends ObjectRun { QueryBuildRange qbrGender; } Override init() method of data source: Public void init() { Super(); qbrGender = this.query().dataSourceTable(tablenum(KKK_CustTable)).addRange(fieldnum(KKK_CustTable, Gender)); } Override executeQuery() of data source: Public void executeQuery()

{ ; qbrGender.value(enum2str(KKK_Gender::Female)); super(); } If filtrations are required on combo, use: qbrGender.value(combobox.valueStr()); and, trigger the executeQuery() method of data source in combo box selectionChange() method: public int selectionChange() { Int ret; Ret = super(); KKK_CustTable_ds.executeQuery(); Return ret; }

List Box: FormListItem item; Int I; ; I = ListView.getNextItem(FormListNext::Selected); While(i!=-1) { Item = ListView.getItem(i); Info(item.text()) I = ListView.getNextItem(FormListNext::Selected, i); } ListView.delete(i); Resources: ImageCtrl.imageName(SysResource::getImagePath(resourcestr(JaiGanesh_JPG)));

Methods handling on Reports: Public boolean fetch() { Boolean ret; Query q = new Query(element.query()); QueryRun qr; KKK_CustTable k; ; Qr = new QueryRun(q); If(qr.prompt()) { While(qr.next()) { K = qr.getNo(1); If((k.CreditLimit *20/100) >= 100) { Element.send(k); } } } } Return true;

Dialogs on Report: Use/override the following methods - dialog() - getFromDialog() - pack() - unpack() Example: Public class ReportRun extends ObjectRun { NoYes showGlassItemMsg; DialogField dfShowGI; #define.CurrentVersion(1)

#localmacro.CurrentList showGlassItemsMsg #endmacro } Dialog() method: Public object dialog(Object dialog) { DialogRunbase dialog = dialog; ; Dialog.addGroup(My Group); dfShowGI = dialog.addFieldValue(TypeId(NoYes), showGlassItemsMsg, Showglass message, Do you want to print the glass error message); return dialog; } getFromDialog() method: Boolean getFromDialog() { ; showGlassItemsMsg = dfShowGI.value(); return true; } Implement pack() and unpack(). Goto fetch() method and use the variable to conditionally execute the programmable section: If(showGlassItemMsg == NoYes::Yes) { Element.execute(2); }

File Handling: Create text file: TextBuffer t = new TextBuffer(); ;

t.setText(I am happy today); t.toFile(c:\\sample.txt);

Read text file: TextBuffer t = new TextBuffer(); ; If(WinAPI::fileExists(c:\\sample.txt)) { t.fromFile(c:\\sample.txt); info(t.getText()); } Else { Throw error(File doesnt exist); } CSV File CommaIO [CommaIO, FileIOPermission, WinAPI] Important methods in CommaIO class: - InFieldDelimiter - InRecordDelimiter - OutFieldDelimiter - OutRecordDelimiter - Status - Read - Write Example: CommaIO commaIO; Container readCon; FileIOPermission fio; KKK_CustTable k; ; If(!WinAPI::fileExists(C:\\Customers_KKK.txt)); Throw error(File doesnt exist); Fio = new FileIOPermission(c:\\CustomersKKK.txt,r); //w to write

Fio.assert(); commaIO = new CommaIO(c:\\CustomersKKK.txt,r); // w to write commaIO.inFieldDelimiter(,); //outFieldDelimiter() commaIO.inRecordDelimiter(\r\n); //outRecordDelimiter() if(commaIO) { While(commaIO.status() == IO_Status::OK) { readCon = commaIO.read(); //write() to write records if(conlen(readCon)>0) { k.AccountNum = conpeek(readCon, 1); k.Name = conpeek(reacCon, 2); k.CreditLimit = conpeek(readcon, 3); k.insert(); } } }

while writing while writing

Reading and Writing XML Files: Classes: XMLDocument XMLTextWriter Important methods: - getElementsByTagName() - length() Reading from XML File: XMLDocument xmlDoc = XMLDocument::newFile(c:\\CustomerKKK.xml); Int I, noOfTags; KKK_CustTable k; ; noOfTags = xmlDoc.getElementsByTagName(CustomerDetails).length(); //Count the tags //XML tag starts with index 0 For(i=0;i<noOfTags;i++)

{ k.AccountNum = xmlDoc.getElementsByTagName(AccNo).item(i).text(); k.Name = xmlDoc.getElementsByTagName(Name).item(i).text(); k.insert(); }

Writing into XML File: XMLTextWriter xmlWriter; KKK_CustTable k; ; xmlWriter = XMLTextWriter::newFile(c:\\KKKCustomersAX.xml); xmlWriter.writeStartDocument(); xmlWriter.writeStartElement(Details); while select k { xmlWriter.writeStartElement(CustomerDetails); xmlWriter.writeElementString(AccNo,k.AccountNum); xmlWriter.writeElementString(Name,k.Name); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.close();

Das könnte Ihnen auch gefallen