Sales Order Import via X++ (add item dimensions) AX 2012

Hi all,

I am currently working on importing sales orders from an external database.

At the lines I want to be able to include dimensions for the item …i.e BusinessUnit, Department e.t.c.
How can I achieve this - am stuck on this. Everything else picks fine except the dimensions.

Thanks.

//struct.add(‘Dimension’, ‘Dimension value’); //format

struct.add(‘Project’, salesStaging.ProjId); //Example

ledgerDimension += struct.fields();

ledgerDimension += struct.fieldName(1);

ledgerDimension += struct.valueIndex(1);

DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);

salesLine.DefaultDimension = DimensionDefault;

I don’t understand your code, maybe because it’s incomplete.

I prefer using DimensionAttributeValueSetStorage class and I recommend the same to you.

This part of the Code I used to create Sales order lines with Dimension.

public void createSalesLine(SalesType _salesType,SalesId _salesId, TransactionId _importid)

{

Struct struct = new Struct();

container ledgerDimension;

DimensionDefault DimensionDefault;

;

salesLine.clear();

salesTable = SalesTable::find(_salesId);

salesLine.initValue(_salesType);

salesLine.initFromSalesTable(salesTable);

salesLine.SalesId = _salesId;

salesLine.ItemId = ‘itemid’;

salesLine.initFromInventTable(InventTable::find(salesLine.ItemId));

salesLine.SalesQty = 1;

//Dimensions

struct.add(‘Department’, ‘Department parameter’);

ledgerDimension += struct.fields();

ledgerDimension += struct.fieldName(1);

ledgerDimension += struct.valueIndex(1);

DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);

salesLine.DefaultDimension = DimensionDefault;

//End Dimensions Part

inventDim.clear();

inventDim.InventSiteId = ‘Site Parameter’;

inventDim.InventLocationId = ‘Location Parameter’;

inventDim = InventDim::findOrCreate(inventDim);

salesLine.InventDimId = inventDim.inventDimId;

salesLine.createLine(

NoYes::Yes, // Validate

NoYes::Yes, // initFromSalesTable

NoYes::Yes, // initFromInventTable

NoYes::Yes, // calcInventQty

NoYes::Yes, // searchMarkup

NoYes::Yes); // searchPrice

}

Your example don’t require any Struct, so you might want to simplify your code before you debug it or share it on forums. By the way, don’t use default dimensions and ledger dimensions interchangeably; they represent different concepts and people won’t understand you. That you likely copied it from some blog doesn’t change that. Many blog posts in this area are pretty weird.

You forgot to tell us what problem you have with your code, so I tried it and got “Invalid BaseEnumType value: 1”. If you want to figure out the right format inside the container, you can try to look at existing services (using getDimensionAttributeValueSetId()) in debugger. But it has never made much sense to me; that’s why I don’t use it and I recommended using DimensionAttributeValueSetStorage. Think again whether you want to ignore this suggestion.

Here is an example:

DimensionAttributeValueSetStorage storage = new DimensionAttributeValueSetStorage();
DimensionAttribute attribute = DimensionAttribute::findByName("Department");
DimensionAttributeValue value = DimensionAttributeValue::findByDimensionAttibuteValue(
                                    attribute, "ID of a department", false, true);

storage.addItem(value);

defaultDimension = storage.save();

Martin Dráb , thanks for the correction and suggestion.