Olaru Mircea
Olaru Mircea

Reputation: 2620

Finding an inventory dimension

I am trying to get an inventDim record if it exists or create a new one otherwise.

InventDim inventDim;

inventDim.InventLocationId = "220";
inventDim = InventDim::findOrCreate(inventDim);
info(inventDim.inventDimId);

I am sure that InventLocationId with the value "220" is already there but anyway, a new one is added.

If i run the above lines again, i will get the last created value, so this time, it's all fine.

By checking in SQL with :

SELECT *
FROM INVENTDIM
WHERE INVENTLOCATIONID = '220'

both lines are returned.

I am able to delete the added line with the following lines:

 select forUpdate inventDim 
    where inventDim.inventDimId == 'the new id';
 inventDim.delete(true);

I can't figure out what am i doing wrong here..

Upvotes: 0

Views: 4364

Answers (3)

Tina van der Vyver
Tina van der Vyver

Reputation: 382

The InventDim table contains values for inventory dimensions. Every record is unique, as in, no record has exactly the same combination of dimensions.

This means that if you are looking for a record with InventLocationId == "220", there can be many records, one with the InventColorId == "Red" and one with InventColorId == "Blue". You'll get further combinations when you combine other dimensions, for example, you can have two more records where the Color is blue, the location is 220 and the InventSizeId is 5 cm or 3 cm.

So with your example above, you are only taking one dimension into account and ignoring the rest. It's completely OK to have more than one record with the InventLocationId set to 220, since one or more of the other inventory dimensions will be different.

If you meant that you want a record where all the other dimensions are empty and InventLocationId is 220, you have to specify that the other dimensions should be blank before you try to find the record.

InventDim          inventDim;
InventDim          inventDimNew;
select inventDim
    where inventDim.InventLocationId == "220"
    && inventDim.ConfigId == ""
    && inventDim.InventSizeId == "";
    //Add more blank dimensions depending on the dimensions active in your system.

buf2Buf(inventDim, inventDimNew);
inventDimNew.inventDimId = '';

info(InventDim::findOrCreate(inventDimNew).inventDimId);

Upvotes: 1

Geoffrey DELMEE
Geoffrey DELMEE

Reputation: 782

Regarding licenses codes, configuration keys, setup, module, and product group you are working with, you may not have the same dimensions active for two different products.

For example, you can follow T-shirts with size and color and caps with color and style. You have similar questions regarding inventory dimensions.

Depending on the product, you may not look for the same set of dimensions. You'll find a good example on how to use it in PriceDisc.findPrice()

So, in your case, the invent location 220 may already have been used and so you may have a record with it. But it seems it was never used alone but with other dimensions (size, color, batch, serial, etc...). Before running the InventDim::findOrCreate() method, make sure to set all relevant dimensions.

Upvotes: 1

Alex Kwitny
Alex Kwitny

Reputation: 11544

It sounds like you don't fully understand the way InventDim works or there may be a caching issue with your All Blank dimension.

The solution is to debug the method \Data Dictionary\Tables\InventDim\Methods\findDim to see how it is trying to find the dimension before deciding to create it.

inventDim.inventLocationId == '220'

is not the same as another record with two fields populated:

inventDim.inventLocationId == '220'

inventDim.inventSiteId == '1'

I've seen caching issues with the AllBlank dimension. Examine these two methods in the debugger as well to see if you see any strangeness. One uses a constant AllBlank while the other uses the global object cache.

InventDim::inventDimIdBlank();

InventDim::findOrCreateBlank();

Upvotes: 1

Related Questions