Friday, April 24, 2009

How to traverse multiple selected lines in a grid control by using X++ code in Microsoft Axapta

This post describes how to use X++ code to traverse multiple selected lines in a grid control in Microsoft Business Solutions - Axapta. Do this when multiple rows of the information in the grid control contain the information which is required to perform the required request.
For example, you can use the following code in the click event of the button if you want to traverse two selected lines when the second row and the fourth row are highlighted in a grid control.

void clicked()
{
CustTable ct;
;
//ct is set to the forms data source and using a cursor goes through each record selected in the grid.
for (ct = DataSource1_ds.getFirst(true) ? DataSource1_ds.getFirst(true): DataSource1_ds.cursor(); ct;ct=DataSource1_ds.getNext())
{
print ct.AccountNum," ",ct.Name;
}
super();
}

Sample X++ code that you can use to disable or to hide a query range in Microsoft Axapta

The following code sample shows how to use X++ code to create a query that contains three ranges. In the code sample, only one specified range can be changed by the end user. In the code sample, the following conditions are true:
• The first range is not shown.
• The second range is shown but cannot be edited.
• The third range can obtain the input from the end user.

static void QueryStatusTest(Args _args)
{
Query q;
Queryrun qr;
QueryBuildRange qbr,qbr1,qbr2;
QueryBuildDataSource qbds;
VendTable vt;
;

// Create an instance of the query class and then provide a name of "Vendors."
q = new query("Vendors");

// Create a data source that connects to the VendTable table.
qbds = q.addDataSource(tablenum(VendTable));

// Use three different field names to create three ranges.
qbr = qbds.addRange(fieldnum(VendTable,AccountNum));
qbr1 = qbds.addRange(fieldnum(VendTable,Blocked));
qbr2 = qbds.addRange(fieldnum(VendTable,Name));

// Set the values for the three ranges.
qbr.value('3*');
qbr1.value(strfmt('(%1 == %2)',fieldstr(VendTable,Blocked),any2int(CustVendorBlocked::No)));
qbr2.value('Office World');

// Set the status of each range.
qbr.status(1);
qbr1.status(2);
qbr2.status(0);

// Create an instance of the QueryRun class.
qr = new QueryRun(q);

// Verify that the QueryRun form is active, and then parse the tablenum value through the VendTable table.
If (qr.prompt())
{
while (qr.next())
{
vt = qr.get(tablenum(VendTable));
print vt;
}
pause;
}

// Show the SQL statement that is produced by the query.
info (qr.query().dataSourceNo(1).toString());

}
Note: The status method provides the function for each range.

Monday, February 25, 2008

Register User Controls and Custom Controls in Web.config

In previous versions of ASP.NET developers imported and used both custom server controls and user controls on a page by adding <%@ Register %> directives to the top of pages like so:

Note that the first two register directives above are for user-controls (implemented in .ascx files), while the last is for a custom control compiled into an assembly .dll file. Once registered developers could then declare these controls anywhere on the page using the tagprefix and tagnames configured.
This works fine, but can be a pain to manage when you want to have controls used across lots of pages within your site (especially if you ever move your .ascx files and need to update all of the registration declarations.
ASP.NET 2.0 makes control declarations much cleaner and easier to manage. Instead of duplicating them on all your pages, just declare them once within the new pages->controls section with the web.config file of your application:

You can declare both user controls and compiled custom controls this way. Both are fully supported by Visual Studio when you use this technique -- and both VS 2005 Web Site Projects and VS 2005 Web Application Projects support them (and show the controls in WYSIWYG mode in the designer as well as for field declarations in code-behind files).
One thing to note above is the use of the "~" syntax with the user-controls. For those of you not familiar with this notation, the "~" keyword in ASP.NET means "resolve from the application root path", and provides a good way to avoid adding "..\" syntax all over your code. You will always want/need to use it when declaring user controls within web.config files since pages might be using the controls in different sub-directories - and so you always need to resolve paths from the application root to find the controls consistently.
Once you register the controls within the web.config file, you can then just use the controls on any page, master-page or user control on your site like so (no registration directives required):

Friday, February 15, 2008

Monday, September 10, 2007

Tuesday, September 4, 2007

Code Coverage of Table Level Methods

In order to enable code coverage you have to follow some naming conventions or override a specific method on your test class:Naming convention: TableName + Test or simply override the testsElementName() method and returnthe name of your table.(also, override the testsElementType and return UtilElementType::Table;