question

Mikael B avatar image
0 Likes"
Mikael B asked Ben Wilson commented

Accessing indexed item label with querySlots()

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?

FlexSim 20.0.10
querystorage systemflexsim 20.0.10indexingqueryslots
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

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 0 ·

1 Answer

·
Lars Christian J2 avatar image
0 Likes"
Lars Christian J2 answered Mikael B commented

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.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

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 0 ·
Mikael B avatar image Mikael B Jason Lightfoot ♦ commented ·

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:

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 0 ·
1619616630662.png (33.1 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.