write a SuiteScript that will convert a NonInvento...
# ask-stanley-ai
d
write a SuiteScript that will convert a NonInventory Item to an Inventory Item
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** Based on the conversations, it seems that there is no direct way to convert a NonInventory Item to an Inventory Item using SuiteScript. The 'Convert to Inventory' action is not available in SuiteScript. However, you can potentially create a new Inventory Item and copy the details from the NonInventory Item. Here is a basic example of how you might do this:
Copy code
javascript
var record = require('N/record');

function convertToInventory(nonInventoryItemId) {
    var nonInventoryItem = record.load({
        type: record.Type.NON_INVENTORY_ITEM,
        id: nonInventoryItemId
    });

    var inventoryItem = record.create({
        type: record.Type.INVENTORY_ITEM
    });

    // Copy fields from nonInventoryItem to inventoryItem
    // This is just an example, you would need to copy all relevant fields
    inventoryItem.setValue({
        fieldId: 'itemid',
        value: nonInventoryItem.getValue({fieldId: 'itemid'})
    });

    inventoryItem.setValue({
        fieldId: 'displayname',
        value: nonInventoryItem.getValue({fieldId: 'displayname'})
    });

    // Save the new inventory item
    var inventoryItemId = inventoryItem.save();

    return inventoryItemId;
}
This script loads a NonInventory Item, creates a new Inventory Item, and copies the 'itemid' and 'displayname' fields from the NonInventory Item to the Inventory Item. You would need to extend this to copy all relevant fields. Please note that this will not preserve the history of the NonInventory Item. If you need to preserve the history, you might need to consider a different approach.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.854736388
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844360471
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.841919
Please provide your feedback on this answer.