I'm looking to make a suiteflow that will take any...
# suiteflow
a
I'm looking to make a suiteflow that will take any inventory with status "Inventory Failed Status" to another Location and bin so it can be reviewed later. Has anyone done this? What issues did you run into?
m
I think you’d need to post an inventory transfer to do this and that is not supported by SuiteFlow
I think it would need to be a script
thankyou 1
a
I am also guessing would need a script for every location? Plant 1 to Failed Inventory location Plant 2 to Failed Inventory location
m
No you could probably do with 1 scheduled or map reduce script
a
ok I'll do some investigation. Thanks as always!
this is the error I'm getting, maybe using the wrong kind of search the feed the script?
m
Can you do it in the regular UI?
a
what do you mean by that?
m
Are you trying to create an Inventory transfer transaction in your script? If so can you manually make an inventory transfer for this item in the UI?
Usually an error like this can be replicated by trying to complete the same task manually then once you troubleshoot that issue it resolves the script
🙌 1
This error seems to indicate that you can’t use bins or statuses with this item
Or maybe you’re setting an inventory number on a non-serialized item?
What data are you setting in the inventory detail. Just bin and status?
a
they are all serialized, maybe 1 or 2 not but the rest are
image.png
m
Can you add logging to return the values for item id bin and lot?
a
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 */
define(['N/search', 'N/record', 'N/log'], (search, record, log) => {

    const FAILED_LOCATION = 13; // Internal ID of "Failed Inventory"
    const REVIEW_BIN = 250;      // Internal ID of "Review" bin

    function execute() {
        // 1. Load saved search of items with Inventory Failed status
        const invSearch = search.load({ id: 'customsearch3117' });

        invSearch.run().each(result => {
            try {
                const itemId = result.getValue({ name: 'item' });
                const fromLocation = result.getValue({ name: 'Bin Number' });
                const qty = result.getValue({ name: 'Quantity' });
                const lot = result.getValue({ name: 'Lot Number' }); // if applicable

                if (!qty || qty <= 0) return true; // skip empty

                // 2. Create Inventory Transfer
                const transfer = record.create({ type: record.Type.INVENTORY_TRANSFER, isDynamic: true });

                transfer.setValue({ fieldId: 'location', value: fromLocation }); // From
                transfer.setValue({ fieldId: 'transferlocation', value: FAILED_LOCATION }); // To

                // Add line
                transfer.selectNewLine({ sublistId: 'inventory' });
                transfer.setCurrentSublistValue({ sublistId: 'inventory', fieldId: 'item', value: itemId });
                transfer.setCurrentSublistValue({ sublistId: 'inventory', fieldId: 'adjustqtyby', value: qty });

                // Inventory detail for bin/lot
                const invDetail = transfer.getCurrentSublistSubrecord({
                    sublistId: 'inventory',
                    fieldId: 'inventorydetail'
                });

                invDetail.selectNewLine({ sublistId: 'inventoryassignment' });
                invDetail.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'binnumber', value: REVIEW_BIN });
                invDetail.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', value: qty });
                if (lot) {
                    invDetail.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'issueinventorynumber', value: lot });
                }
                invDetail.commitLine({ sublistId: 'inventoryassignment' });

                transfer.commitLine({ sublistId: 'inventory' });

                const transferId = transfer.save();
                log.audit('Transfer Created', `ID: ${transferId}, Item: ${itemId}, Qty: ${qty}`);

            } catch (e) {
                log.error('Error moving failed inventory', e.message);
            }
            return true; // continue loop
        });
    }

    return { execute };
});
this is the whole thing, so your saying add more to log.error
I do see my search showing doubles of almost everything
m
Is this an item search?
a
inventory detail search
m
Yes. I usually use log debug but more logging will help you troubleshoot
a
item search wouldn't let me pull status
m
What joins are you using in this search
a
I feel super dumb but what do you mean by joins
m
Like at the bottom of the fields you can select from it says Item Fields… Location Fields… Etc
Then you can add a field from the item or location record in your results
Did you use any of those
a
these are what I used in Criteria and Results
m
Maybe try an inventory balance search instead
a
well that search looks a lot better... let me try again here