RSS

Tag Archives: Axapta

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

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

How to delete unused Financial Dimension

yesterday I came across the following issue  and thought I’d share my findings and solution.

I’ve setup a chart of accounts and shared it between¬†3 companies.(one of them a test company).i have mapped one ledger account (Main Account) with bank accounts of all three¬†companies.I have attached a “Test” account structure.and made a couple of postings in the test company.

when I want to modify a main account or delete a bank account that was not used (but defined with a main account).The message is the bank account cannot be deleted because the financial dimension related to the account has transactions.

A financial dimension value is based on the <dimension value> record and has been used on a transaction. You cannot delete the <dimension value> record.

error

We knew these dimension values weren’t used on any posted or un-posted transactions, so the expectation was that we could simply delete these without any issues. So you can imagine the surprise when we tried to delete the dimension values(Ledger,Bank,customer,vendor etc.)

The error means that there are some existing reference records.I can explain the reason for the message and why you are not able to delete the main account, but unfortunately cannot give you a good solution for how to fix it.

When you add new records to financial dimension entities (Main account, Department, Cost center, etc.), they are merely available for use and can be immediately deleted.  However, as soon as they are actually used, additional records are created in tables such as DimensionAttributeValue, DimensionAttributeValueCombination, DimensionAttributeLabelValue, and many others part of the dimension framework.

These tables are used in storing data for a Ledger dimension ¬†Dynamics AX 2012. There will be multiple entries in these tables for a single ledger dimension.AX provides no mechanism for deleting these records.The solution will be to make a utility that deletes all the record in those tables that don’t have any reference in any other tables.

To find out which DimensionAttributeLevelValue record corresponds to the main account, you need to use a few more tables.

LedgerChartOfAccountStructure –> Links COA to account structure

DimensionHierarchy –> AKA Account structure table. ¬†Also links to LedgerChartOfAccountsStructure, so you match the MainAccount by COA all the way to the account structure.

DimensionAttributeValueGroup –> Stores groups of values for the dimension set, which is linked to both DimensionAttributeLevelValue and DimensionHierarchy.

So you can start from DimensionAttributeLevelValue and drill back (or join) in this way…

DimensionAttributeLevelValue.DimensionAttributeValueGroup = DimensionAttributeValueGroup.Recid

DimensionAttributeValeuGroup.DimensionHierarchy = DimensionHierarchy.Recid

DimensionHierarchy.Recid = LedgerChartOfAccountsStructure.DimensionHierarchy

LedgerChartOfAccountsStructure.ChartOfAccounts = MainAccount.LedgerChartOfAccounts

MainAccount.MainAccountId = ‘Your account number’

Simple Solution

1) Error occurring as there are record exist in the DimesionAttributeLevelValue table for the customer

2) Go to the DimensionAttributeLevelValue table –> filter by Bank,Vendor,Customer¬†number in the DisplayValue field –> you can see the records exist in the table for the customer

3) Delete the record from the table

4) After this try deleting the Bank,Vendor,Customer.

(It will allow you to delete the Bank,Vendor,Customer record)\

Happy Daxing. ¬†ūüôā

 

Tags: , , , , , ,

Concatenate text or Number fields

I have multiple text fields in a table I wish to display as one field on a form.

there could be few choices, you can use like that

str output;

output = strfmt(“%1 %2 %3 %4 %5”, field1, field2, field3, field4, field5);

// similar u can add more fields.

ūüôā Happy Daxing

 

Tags: , , , ,