Accessing indexed item label with querySlots()

Accessing indexed item label with querySlots()

mikael_bs
Not applicable
103 Views
4 Replies
Message 1 of 5

Accessing indexed item label with querySlots()

mikael_bs
Not applicable

[ FlexSim 20.0.10 ]

I wonder if its possible to use indexed item labels with the querySlots command. I use this line of code to check if each zone already contains a SKU, to more evenly distribute SKUs across the zones.

Array skusInZone;
for (int i=1; i<=18; i++) {
            int Zone = i;
            Array slots = Storage.system.querySlots("WHERE zone = $2 AND slot.slotItems.length >= 1 AND slot.slotItems[1].item.SKU = $1 LIMIT 5", 0, SKU, Zone);
            skusInZone.push(slots.length);
        }

There are a total of 18 zones, and each zone consists of about 4000 slots, so I would like to make the query faster. zone is an indexed slot label. I would prefer to avoid painting slots with a SKU label. I have already indexed the item label SKU in the storage system. Is it possible to use the indexed item label in a querySlots() command?

0 Likes
Accepted solutions (1)
104 Views
4 Replies
Replies (4)
Message 2 of 5

lars_jacobsen_ScandiSim
Advocate
Advocate
Accepted solution

If possible, please provide a sample model. For the storage system query to use an index, you need to specify a label directly, otherwise it is evaluated as FlexScript and will not use an index. Thus instead of writing "slot.slotItems[1].item.SKU", try just writing the label "SKU" in your query.

0 Likes
Message 3 of 5

The index relates to the type of query - so using findItem() could use the item indices while findSlot() would reference those of slots. Other wise you couldn't have the same label - say 'SKU' on both the slot and the items - you'd have to call them slotSKU and itemSKU in order for the query to know which you're checking.


0 Likes
Message 4 of 5

mikael_bs
Not applicable

I had the same feeling but I tested it out just to be sure, and the index does relate to the type of query. Here is an image from the test:

38867-1619616630662.png

The slots doesnt have a SKU label, so the query couldnt find anything.

I think a workaround without labeling the slots could be to give slot.items the indexed label zone and use queryItems() instead. With some coding I should be able to stop the query from pulling multiple slotitems from the same slot, which I think should give the same result as querySlots(). If I try this, and it turns out successful, I will give an update in this comment chain.

0 Likes
Message 5 of 5

Ben_WilsonADSK
Community Manager
Community Manager

Hi @Mikael B, was Lars Christian J2's answer helpful? If so, please click the red "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes