web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

(0) ShareShare
ReportReport
Posted on by

I have added a new form control and added a lookup in the method. My code looks like this. Everytime I keying a relevant financial dimension into the new form control, I get error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called." Please can you help?

public void lookup()
{
SysTableLookup sysTableLookup;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
Query query = new Query();
DimensionAttribute dimAttr = DimensionAttribute::find(LedgerParameters::find().TSJournalSubcodeAttribute);
;

sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag), this);
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value));
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));

queryBuildDataSource = query.addDataSource(tableNum(DimensionFinancialTag));
queryBuildDataSource.addOrderByField(fieldnum(DimensionFinancialTag, Value));

sysTableLookup.parmQuery(query);

if (sysTableLookup)
{
sysTableLookup.performFormLookup();
}
}

I have the same question (0)
  • Martin Dráb Profile Picture
    239,067 Most Valuable Professional on at

    Please use the debugger to find out the call stack leading to the exception. Then please share it with us. It doesn't seem to be called from lookup() at all.

    By the way, please use Insert > Insert Code (in the rich-formatting view) to paste source code. It preserves indentation, which makes code much easier to read:

    public void lookup()
    {
    	SysTableLookup sysTableLookup;
    	QueryBuildDataSource queryBuildDataSource;
    	Query query = new Query();
    	DimensionAttribute dimAttr = DimensionAttribute::find(LedgerParameters::find().TSJournalSubcodeAttribute);
    	;
    
    	sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag), this);
    	sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value));
    	sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
    
    	queryBuildDataSource = query.addDataSource(tableNum(DimensionFinancialTag));
    	queryBuildDataSource.addOrderByField(fieldnum(DimensionFinancialTag, Value));
    
    	sysTableLookup.parmQuery(query);
    
    	if (sysTableLookup)
    	{
    		sysTableLookup.performFormLookup();
    	}
    }

  • Community Member Profile Picture
    on at

    Hi Martin,

    This is where it throws error:

    public int addItemValues(RecId _dimensionAttributeId, RecId _dimensionAttributeValueId, HashKey _dimensionAttributeValueHashKey)
    {
    int i;

    // Unable to add a zero dimension attribute as that does not mean anything
    if (_dimensionAttributeId == 0)
    {
    throw error(Error::wrongUseOfFunction(funcname()));
    }

    pastedimage1615866961034v1.png

  • Martin Dráb Profile Picture
    239,067 Most Valuable Professional on at

    Okay, and what is the call stack (the sequence of method calls) leading to addItemValues()?

  • Community Member Profile Picture
    on at

    Hi Martin, I looked into the code and found that here is where it fails.

    public static DimensionDefault setDimensionDLG(DimensionDefault _dimension, RefRecId _dimensionAttributeId, DimensionValue _dimensionValue, boolean _createIfNecessary = false)
    {
        DimensionAttribute                dimAttr;
        DimensionAttributeValue           dimAttrValue;
        DimensionAttributeValueSetStorage dimAttrValueSetStorage;
        ;
    
        if (!_dimensionAttributeId)
        {
            return _dimension;
        }
    
        dimAttr = DimensionAttribute::find(_dimensionAttributeId);
    
        dimAttrValueSetStorage = DimensionAttributeValueSetStorage::find(_dimension);
    
        if (_dimensionValue)
        {
            dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, _dimensionValue, false, _createIfNecessary);
            dimAttrValueSetStorage.addItem(dimAttrValue);
        }
        else
        {
            dimAttrValue = DimensionAttributeValue::find(dimAttrValueSetStorage.getValueByDimensionAttribute(dimAttr.RecId));
            dimAttrValueSetStorage.removeDimensionAttributeValue(dimAttrValue.RecId);
        }
    
        return dimAttrValueSetStorage.save();
    }
    

    pastedimage1615960756523v1.png

  • Verified answer
    Martin Dráb Profile Picture
    239,067 Most Valuable Professional on at

    It means that the value doesn't exist yet. If you want to create it automatically, call setDimensionDLG() with _createIfNecessary = true.

    Unfortunately I have no idea where you're calling setDimensionDLG(), because you didn't share the call stack. You'll have to look at it by yourself.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 495 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 315 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans