RSS

Tag Archives: AX2012

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

Advertisements
 

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: , , , ,

Document Generic document could not be created-AX 2012 Excel Addin

yesterday I was trying to import data from excel to ax 2012 through office addins in newly created staging table.

I have followed export procedure successfully but could not import the data in ax staging table and my publishing failed getting following error

excel addins.PNG

I googled this error and most of them suggested build incremental CIL.I also did the incremental CIL which solved my issue.

Reference :https://community.dynamics.com/ax/f/33/t/69736

 

Happy Daxing ūüôā

 

Tags: , , , , ,

Cannot insert multiple records in Security user role (SecurityUserRole). The record already exists.

I have made a copy of production environment and restored on development environment and deleted all the users from userinfo table.

I got an request to provide  access to an user but whenever i tried to import new user i started getting error.

Cannot insert multiple records in Security user role (SecurityUserRole).

This error itself giving you solution of the problem,we have to delete the record from this table with USER_= “new user”.

Route cause: The route cause of this error is inconsistency between userinfo table and securityUserRole.

 

Solution: Open SQL Server Management Studio, SQL DB, Select the MicrosoftDynamicsAX database and run the below query

delete from dbo.SECURITYUSERROLE where USER_ = ‘deepakKal’

To check user details run:

select * from dbo.SECURITYUSERROLE.

Now if you will try again to add same user then you will see its added without any error.

Happy Daxing ūüôā

 

Tags: , , , ,

Error Cannot create a record in TmpLedgerJournalPost TmpLedgerJournalPost). Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record.

There is a bug with changeCompany keyword which prevents usage of the same initialized table buffer in different companies. For example, in the following code:

LedgerJournalTrans ledgerJournalTrans;

changecompany(company)
{
ttsbegin;

if(this.parmLedgerJournalTable().RecId)
{
tmpLedgerJournalPost.JournalNum = this.parmLedgerJournalTable().JournalNum;
tmpLedgerJournalPost.Branch = ledgerTransactionVoucher.Branch;
tmpLedgerJournalPost.VoucherType= ledgerTransactionVoucher.VoucherType;
tmpLedgerJournalPost.TransDate = ledgerTransactionVoucher.TransDate;
tmpLedgerJournalPost.Company = ledgerTransactionVoucher.Company;
tmpLedgerJournalPost.insert();
}
//further operations
}

crosscompany error

Issue
On usage of change company keyword also the table buffers will hold the old values, so its necessary to explicitly clear the table buffer by assigning null.

Solution:

i was inserting the records through code in multiple companies using the same table buffer and i had to assign null to the table buffer after switching the company to resolve this issue as it was not assigning the buffer to null as expected.

LedgerJournalTrans ledgerJournalTrans;

changecompany(company)
{
// nulling
ledgerJournalTrans = null;
ledgerJournalTable = null;
// nulling
ttsbegin;

if(this.parmLedgerJournalTable().RecId)
{
tmpLedgerJournalPost.JournalNum = this.parmLedgerJournalTable().JournalNum;
tmpLedgerJournalPost.Branch = ledgerTransactionVoucher.Branch;
tmpLedgerJournalPost.VoucherType= ledgerTransactionVoucher.VoucherType;
tmpLedgerJournalPost.TransDate = ledgerTransactionVoucher.TransDate;
tmpLedgerJournalPost.Company = ledgerTransactionVoucher.Company;
tmpLedgerJournalPost.insert();
}
//further operations
}

Happy Daxing ¬†ūüôā

 

Tags: , , , , , ,

Container and text fields not allowed in update_recordset setting expression

Error Message :

Container and text fields not allowed in update_recordset setting expression

error

Cause: Dynamics AX does not allow you to use an unbounded string in a setting  and where clause.

Solution:

You must use a ‚Äėbounded‚Äô string. To do this you must declare Extended Data Type¬†e.g.¬†ErrorMsg

Example:

error2

 

Tags: , , , , ,