RSS

Category Archives: X++

To Debug Ax Service Operations Framework

To debug the Dynamics Ax, service operations (SysOperationService) framework, change the following method as follows…

Classes –> SysOperationRPCFrameworkService –>runServiceOperation

 

/*return SysDictClass::invokeStaticMethodIL(classStr(SysOperationServiceController),

                                        staticMethodStr(SysOperationServiceController, runServiceOperation),

                                        [controllerClassId, packedController]);*/

return SysOperationServiceController::runServiceOperation([controllerClassId, packedController]);

Credit :https://paruvellas.wordpress.com/2012/08/13/to-debug-ax-service-operations-framework/

 

 

Tags: , , ,

How to select multiple records from lookup-Part-1(SysLookupMultiSelectCtrl)

Today i would share how to create a lookup to select multiple items in Dynamics AX 2012 forms.

In normal lookup methods we can only select one item at a time but in AX 2012 has introduced new class SysLookupMultiSelectCtrl to achieve the same without any hassle.

There are multiple ways to achieve the same but today i will demonstrate how can we have a site lookup with provision to select more then one item selection on parameter form in dynamics ax.

Multiselect lookup.png

Steps:

  1. Create a Query named InventSiteQR that will contains data source e. InventSiteas shown in the below figure.

QueryMultiple lookup.PNG

2.Create the control on the form, set the auto declaration property to yes

Multiselect lookup

3.Declare instance of class SysLookupMultiSelectCtrl In the Class Declaration of the form:

public final class FormRun extends ObjectRun
{
 SysLookupMultiSelectCtrl msCtrlSite;
}

 

4.Write below code in the Init method of the form:

public void init()
{
 msCtrlSite = SysLookupMultiSelectCtrl::construct(element, SplitCostingProd, 
querystr(InventSiteQR),false, [tableNum(InventSite), fieldNum(InventSite, SiteId)]);
}

5.Add new field container type on parameter table named InventSiteCon

6.Write below code on the active method of form parameter table data source to update the control on load of the form:

public int active()
{
if(ProdParameters.InventSiteCon)
 msCtrlSite.set(ProdParameters.InventSiteCon);
 else
 msCtrlSite.set(conNull());
}

7.Write below code on the modified method of form control to get the selected record values from lookup and update those values to parameter Table:

public boolean modified()
{
 boolean ret;
 container conSite;
 RefRecId recid;
 int i;
 InventSite inventSite;
 container roleIds, roleNames;

 ret = super();
 conSite = msCtrlSite.get();
 for(i = 1;i<=conLen(conSite);i ++)
 {
 recid = conPeek(conSite,i);
 select firstOnly inventSite where inventSite.RecId == recid;
 if(inventSite.RecId)
 {
 roleIds += inventSite.RecId;
 roleNames += inventSite.SiteId;
 }
 }
 ProdParameters.InventSiteCon = [roleIds,roleNames];
 return ret;
}

 

Thats it. Happy Daxing 🙂

 

Tags: , , , , , ,

Disable Form grid column automatic sorting feature

I have been asked by customer to enable sorting only on one field and one should not be able to sort by using other grid fields/controls.

in simple words he wants me to disable automatic sorting feature on other fields on grid except one so that when the user clicks the column header, the order displayed would not change.

i found dynamics community conversation to achieve this quick manner.I have added an override method sort() on each grid control where i wants to disable automatic sorting and also blocked super.

sort method

 

public int sort(SortOrder _sortDirection)
{
 int ret;

 //ret = super(_sortDirection);

 return ret;
}

 

Happy Daxing 🙂

References :
How can I disable the automatic sort on the grid?
Preventing users from sorting a grid

 

Tags: , , , , ,

Fill color in Grid records based on condition flag in AX

My client requirement was to change the grid row’s color in dynamics ax 2012 on the condition basis.

There is a method displayOption() method on a form data source which can be useful to highlight particular rows on grid, based on the data in the record. displayOption() method will execute once for each record before the record is displayed on the form.

public void displayOption(Common _record, FormRowDisplayOption _options)
{
 #define.DeepSkyBlue(0, 191, 255)

 if (_record.(fieldnum(ProdTable,ProdStatus))==ProdStatus::ReportedFinished)
 {
 _options.backColor(WinAPI::RGB2int(#DeepSkyBlue));
 }

 super(_record, _options);
}

Happy Daxing 🙂

Reference :
Highlighting record in Grid

How to change grid row color in listpage form in Dynamics Ax 2012

 

Tags: , , , , , , , ,

How to pass more than one record between two forms?

I come through one client requirement to pass multiple selected records from one form to another,The Scenario is when user opens Form-A, selects multiple records and then clicks a button that opens Form-B. there Form-B will receive only those selected records at Form-A.

There are multiple ways to pass single selected record and we can also pass multiple records through container or temporary table for instance:

Write below code on clicked event of menu item button on Form-A which will open Form-B,This is typical and traditional way to achieve this requirement in all versions of AX.

int         recordsCount;
CustTrans custTrans;
container   con;
Args        args = newArgs();

// gets the total records selected
recordsCount = custTrans_ds.recordsMarked().lastIndex();
custTrans= custTrans_ds.getFirst(1);
while(cusTrans)
{
    // storing recid of selected record in container
    con = conIns(con,1, custTrans.RecId);
    custTrans = custTrans_ds.getNext(); // moves to next record
}   
// passing container converted to string 
args.parm(con2Str(con,','));

Then on Form-B, we need to override the init() method to receive the args that we created on clicked event

public void init()
{
    container   con;
    int         i;
    super();       
    // string to container
    con = str2con(element.args().parm(),'','');    
    // for sorting
    for(i = 1;i<= conLen(con) ;i++)
    {
        custTrans_ds.query().dataSourceTable(Tablenum(custTrans)).
       addRange(fieldNum(cusTrans,RecId)).value(SysQuery::value(conPeek(con,i)));
    }
} 

In Dynamics AX 2009,MultiSelectionHelper class is introduced but commonly used in AX 2012 on multiple places, we can write minimal code to achieve the same.

Enable the multi-select property to Yes and on Form-B, we need to override the init() method to load the selected record at Form-A

public void init()
{
    MultiSelectionHelper helper;
    super();       
    if (element.args() && element.args().caller() && element.args().record())
    {
        this.query().dataSourceTable(tableNum(CustTrans)).clearDynalinks();
        helper= MultiSelectionHelper::createFromCaller(element.args().caller());        
        helper.createQueryRanges(this.query().dataSourceTable(tablenum(CustTrans)), 
        fieldstr(CustTrans, RecId));
    }
}

 

 

Happy Daxing 🙂

Reference: http://stackoverflow.com/questions/29555888/how-to-pass-more-than-one-record-between-two-forms

 

Tags: , , , ,

List all the Base Enumerations in AX 2012

Today i got a requirement to traverse and list down all enumerations available in AOT. I also needed the list of all Base Enums elements with their label & value. The result was a simple but powerful script which will traverse all nodes of a Base enumerations to find all enumerations elements.

The below code will populate the list of of Base enumerations under AOT node.
static void Job_ListBaseEnumObjects(Args _args)
{
// #AOT is defined in the AOT under Macros.
#AOT
TreeNode treeNode;
EnumId enumId;
Counter counter;
SysDictEnum sysDictEnum;
BaseEnumList baseEnumList;
;

treeNode = TreeNode::findNode(#BaseEnumsPath);
treeNode = treeNode.AOTfirstChild();
while(treeNode)
{
sysDictEnum = new SysDictEnum(enumName2Id(treeNode.treeNodeName()));
baseEnumList.clear();
baseEnumList.BaseEnumID = enumName2Id(treeNode.treeNodeName());
baseEnumList.BaseEnumName = treeNode.treeNodeName();
baseEnumList.ElementCount = int2str(SysDictEnum.values());
baseEnumList.insert();
for (counter=0;counter<SysDictEnum.values();counter++)
{
baseEnumList.clear();
baseEnumList.BaseEnumID = enumName2Id(treeNode.treeNodeName());
baseEnumList.BaseEnumName = treeNode.treeNodeName();
baseEnumList.ElementLebel = SysDictEnum.index2Label(counter);
baseEnumList.ElementValue = int2str(SysDictEnum.index2Value(counter));
baseEnumList.insert();
}
treeNode = treeNode.AOTnextSibling();
}
}

I extracted table data in excel after pressing CTRL+T on browsed table.

Base Enums

Happy Daxing 🙂

 

Compilations errors in Payroll classes-Symmetry

Today We were migrating existing production environment to new production environment hardware.

So I have done fresh instillation of dynamics ax 2012 R CU8 on new machine.I have imported model store and restored Microsoft Dynamics AX(OLTP)database without any error.

when i initiated compilation on machine then got around 22 errors in ax standard classes like variable not declared  or syntax error in payroll classes.

Compiler Output Payroll Classes

 

“Symmetry.TaxEngine.STEPayrollCalculator ste,steApplicable”

There are many blog written to resolve this symmetry error.Most of them suggested to add ste.net.dll file from server and client bin folders in AOT ->References node

C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin

C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin

Variable Symmetry has not been declared Compilation error in Ax 2012

AX2012 R3 CU8 – AOT Compile Errors on Payroll Classes related to Symmetry DLL

but it didn’t work for me and  many more. I identified one more simple solution because i faced similar issue in AX 2009 related to missing of system Base Enum.

I uninstalled  AX client and did installation again and restarted the AX services.when i tried compilation again then there was no syntax error left.

 

Happy Daxing 🙂