i need to create a script that for a given item an...
# ask-stanley-ai
m
i need to create a script that for a given item and bom id it creates a new work order how to do a transform operation creating a new work order for a given bom that is not the default one
c
AI generated answer (using internal Slack threads):
To create a script that creates a new work order for a given item and BOM ID, you can use SuiteScript's record transformation functionality. Here's a basic example of how you might do this:
Copy code
javascript
var record = require('N/record');

function createWorkOrder(itemId, bomId) {
    var workOrderRecord = record.transform({
        fromType: record.Type.ASSEMBLY_ITEM,
        fromId: itemId,
        toType: record.Type.WORK_ORDER,
        isDynamic: true,
    });

    workOrderRecord.setValue({
        fieldId: 'bom',
        value: bomId
    });

    var recordId = workOrderRecord.save({
        enableSourcing: true,
        ignoreMandatoryFields: true
    });

    return recordId;
}
In this example, the
createWorkOrder
function takes an item ID and a BOM ID as arguments. It uses the
record.transform
method to create a new work order from the given assembly item. It then sets the BOM field of the new work order to the given BOM ID using the
setValue
method. Finally, it saves the new work order and returns its ID. Please note that this is a simplified example and you may need to adjust it to fit your specific needs. For example, you might need to set additional fields on the work order, handle errors, or add logging. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.831210375
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.818358302
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.817971826
Please provide your feedback on this answer.