Skip to main content

Notifications

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();
}
}

  • Verified answer
    Martin Dráb Profile Picture
    232,968 Most Valuable Professional on at
    RE: Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

    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.

  • Community Member Profile Picture
    on at
    RE: Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

    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

  • Martin Dráb Profile Picture
    232,968 Most Valuable Professional on at
    RE: Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

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

  • Community Member Profile Picture
    on at
    RE: Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

    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
    232,968 Most Valuable Professional on at
    RE: Error "Function DimensionAttributeValueSetStorage.addItemValues has been incorrectly called. "

    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();
    	}
    }

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,165 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans