Welcome to Dynamics Ax blog for learning, sharing and transferring dynamics AX knowledge and all related topics to AX
Dynamics AX tools and tutorials: UtcDateTime in Dynamics AX 2009
Passing Parameters to a Report in Dynamics AX
Creating reports in AX is generally ‘a walk in the park’ even for the new developers not fully acquaint with the syntax of X++. However, it sometimes becomes challenging to understand how the parameters could be passed to a report when you want to initiate that report from a form.
{
ReportRun reportRun;
;
reportRun = classFactory.reportRunClass(args);
reportRun.init();
reportrun.run();
//hello
}
{
;
try
{
if(element.args().parm())
{
this.query().dataSourceTable(tablenum(PurchReqTable))
.addRange(fieldnum(PurchReqTable, PurchReqId)).value(element.args().parm());
this.query().interactive(false);
super();
}
}
{
info(“Error in init method”);
}
Get day, month and year from date in axapta x++
//Get day from date
dayOfMth(systemdateget())
//Get month from date
mthOfYr(systemdateget())
//Get year from date
year(systemdateget())"
SysTableLookup class - Axaptapedia
- Create the sysTableLookup object
- Create the query which will be used to select the lookup data
- Specify the fields which will be shown on the lookup
- Perform the lookup
public void lookup()
{
Query query = new Query();
QueryBuildDataSource dsCustTable;
QueryBuildDataSource dsCustTrans;
// Instantiate sysTableLookup object using table which will provide the visible fields
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(CustTable), this);
;
// Create the query. Only select customers where blocked != All and one more more transactions
// exist with no closed date
dsCustTable = query.addDataSource(tableNum(CustTable));
dsCustTable.addRange(fieldNum(CustTable, Blocked)).value(queryNotValue(CustVendorBlocked::All));
dsCustTrans = dsCustTable.addDataSource(tableNum(CustTrans));
dsCustTrans.relations(true);
dsCustTrans.joinMode(JoinMode::ExistsJoin);
dsCustTrans.addRange(fieldNum(CustTrans, Closed)).value(queryValue(dateNull()));
// Set the query to be used by the lookup form
sysTableLookup.parmQuery(query);
// Specify the fields to show in the form. In this case we have chosen
// Account number, name, and dimension one.
sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupfield(fieldId2Ext(fieldNum(CustTable, Dimension), 1));
// Perform the lookup
sysTableLookup.performFormLookup();
}
public static void lookupCustOpenTrans(FormControl _callingControl)
{
Query query = new Query();
QueryBuildDataSource dsCustTable;
QueryBuildDataSource dsCustTrans;
// Instantiate sysTableLookup object using table which will provide the visible fields
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(CustTable), _callingControl);
;
... remainder of code from above ...
}
public void lookup()
{
;
CustTable::lookupCustOpenTrans(this);
}
Lookups - Axaptapedia
Lookups
Contents[hide] |
Automatic lookups
Introduction
Displayed fields
How does Axapta determine which fields to use?
- The field(s) responsible for the relation (in the order of the content of the relation-treenode of the table or the extended datatype)
- TitleField1
- TitleField2
- The first field of every index of the table (in the order of the index-id)
- Item number (ItemId)
- Item name (ItemName)
- Item group (ItemGroupId)
- Search name (NameAlias)
- Item type (ItemType)
- Dimension group (DimGroupId)
How can we change which fields are displayed?
Manual lookups
Calling the standard lookup behaviour from code
Changing the lookup form used
Construct a standard lookup form, based on your own query
Use an entirely new lookup form
Document Handling in AX – setup and Example
On the Tools menu, select Options.
Under Document handling, select Document handling active.
Select Update toolbar line button to highlight the Document handling icon on the toolbar when you select a record with documents references.
Documents are stored in a default document archive directory and before you start creating documents, you must select the location in theParameters form.
Click Basic > Setup > Document management > Parameters.
In Archive directory, type the path to the archive directory, or use the browse button (…) to select a folder on your network.
Select the Number sequences tab.
In the Number sequence code list, select the number sequence to use for naming your documents.
The document management system handles several types of documents including letters, worksheets, and simple notes. Before you can create documents of a certain type, the document type must be created in the Document type form.
By default, all documents are stored in the Archive directory selected on the Parameters form. However you can select alternative folders for the individual document types.
Also by default, all document types are available from all forms, but some document types are only relevant for certain tables, such as, if you only want to create customer letters for records in the Customers form. When you associate a document type with a specific table, it is not possible to create any documents of that type, in other tables.
Create new document type
Click Basic > Setup > Document management > Document types.
Press CTRL+N to create a new document type.
In Type, type a code for the document type.
In Name, type a descriptive name for the document type.
In the Job description list, select the type of document to create.
In the Group list, select a group for the document type.
Now, I would like to explain document handling with an example for sales orders form of DOC type.
Initially set the parameters for document handling.
Go to – >Basic -> setup -> Document Management – > Parameters form
set the archive diretory path ( where the document has to be stored like c:\AxDocuments). Remember when ever u create document for a record, the document gets stored in the above location specified.
Check – use Active document table checkbox.
In the number sequences tab - select the number sequence you would like to use for the documents.
Then, If you want to enable documents for salestable – Go to – > Basic -> setup -> Document Management – > Active document tables form . Then select the name of the table here as salestable and in enable the always enabled checkBox.
Now when you open the salestable form you can find the document handling enabled on the toolbar for the salestable form. Double click the document handling icon and create a new document for that record by clicking the new button and selecting the Document menuitem button.Now you can create documents for the salestable.Once you create documents the documents will be stored in the archive path selected in the parameters form.
When ever u create a document, it hits docuref and docuvalue tables.
In the docuref,it creates a record with the tableid of the salestable, the record id of the salestable and the dataareaid ..etc..and correspondingly a record gets generated in the docuvalue with all the filenames, extensions,path etc
To view the documents in the salestable from itself, i mean in the gird itself here is the way…
Open the salestable form, Then , I would like to use icons for every record in the salestable.So i will write a display method at the salestable level.
//BP Deviation Documented
display smmDocIconNum
showDocHandIcon()
{
#macrolib.resource
;
if ((select firstonly docuRef where
docuRef.RefCompanyId == this.DataAreaId && docuRef.RefTableId ==
this.TableId && docuRef.RefRecId == this.RecId).RecId)
{
return #RES_NODE_DOC;
}return #RES_AM_NEW;
}
Now create a new window control in the gird. Add the datasource as salestable and datamethod as showDocHandIcon.
The main class where all the business logic is written is docuAction Class. Now i am going to use this class to open the documents for the records.
Now please override the Mouseup() method of the window control
public int
mouseUp(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)
{
int ret;
args args;
docuRef
docuRef;
;
ret =
super(_x, _y, _button, _Ctrl, _Shift);element.showDocument();
// Method at form level
return ret;
}
Now add showDocument() method at form level
void showDocument()
{
args args;
docuref docuref;
;args = new args();
docuRef =
docuref::find(salesTable.dataAreaId,tablenum(SalesTable),salesTable.RecId,today());
args.record(docuRef);
args.parmEnumType(enumnum(Docucode));
args.parmEnum(Docucode::Open);
docuaction::main(args);
}NOW YOU CAN VIEW YOUR DOCUMENTS FROM THE GRID ITSELF BY DOUBLE CLICKING THE WINDOW CONTROL.
Axapta Dialog Validation - Stack Overflow
Here is an example in AX 2009 of how to build a simple dialog using the RunBase class. In it I create a class called DialogExample and derive from RunBase. To show the dialog you simply need to run the class, but typically this would be done by pointing a MenuItem at the class.
public class DialogExample extends RunBase
{
DialogField dialogName;
Name name;
#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
name
#ENDMACRO
}
Object dialog()
{
Dialog dialog = super();
;
// Add a field for a name to the
dialog. This will populate the field with
// any value that happens to
be saved in name from previous uses of the
// dialog.
dialogName =
dialog.addFieldValue(TypeId(Name), name);
return dialog;
}
boolean getFromDialog
()
{
;
// Retrieve the current value from the dialog.
name
= dialogName.value();
return true;
}
boolean validate(Object _
calledFrom = null)
{
boolean isValid;
isValid = super(_calledFrom
);
// Perform any validation nessecary.
if (name != 'abc')
{
isValid = checkFailed('Name is not equal to abc') &&
isValid;
}
return isValid;
}
Name parmName()
{
;
return name;
}
public container pack()
{
return
[#CurrentVersion,#CurrentList];
}
public boolean unpack(container
_packedClass)
{
int version = conpeek(_packedClass, 1);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = _packedClass;
break;
default :
return false;
}
return true;
}
public static void main(Args args)
{
DialogExample DialogExample;
;
dialogExample = new dialogExample();
// Display the dialog. This only returns true if the the user clicks "Ok"
// and validation passes.
if (dialogExample.prompt())
{
// Perform any logic that needs to be run.
info(dialogExample.parmName());
}
}
Typically in this scenario logic that needs to be run would be put in a run method on the
class and then called into from main if the Ok button is clicked.
Since the run method would be an instance method this gets rid of the need for the parm methods to access the value of the field on the dialog.