Is this normal - I have a UE script that runs afte...
# suitescript
c
Is this normal - I have a UE script that runs after submit. It runs a search for item quantities on order, and needs to include the sales order that was just saved in the results. When an existing sales order is edited, that sales order is included in the searches results. When a new sales order is saved, it is NOT included in the search results. I thought the after submit entry point triggers AFTER the record is saved.
c
Double check where you're getting the internal id from, and make sure it's set
Just guessing without seeing code
c
Code might help, yeah. I have a field on a few item's records to keep track of the total number on sales orders. This script is supposed to update that number after a sales order is saved.
Copy code
function afterSubmit(context) {
//List of items to update
let mums = [49318, /*54640,*/ 48891, 48892, 48893]

for (let i = 0; i < mums.length; i++) {

    let lineNum = context.newRecord.findSublistLineWithValue({
        sublistId: 'item',
        fieldId: 'item',
        value: mums[i]
    })

    if (lineNum == -1) continue

    search.create({
        type: "salesorder",
        filters:
            [
                ["mainline", "is", "F"],
                "AND",
                ["closed","is","F"], 
                "AND", 
                ["type", "anyof", "SalesOrd"],
                "AND",
                ["item", "anyof", mums[i]],
                "AND",
                ["shipdate", "within", "8/1/2023", "12/30/2023"]
            ],
        columns:
            [
                search.createColumn({
                    name: "quantity",
                    summary: "SUM",
                    label: "Quantity"
                    })
            ]
    }).run().each(result => {
        let prebookedQty = result.getValue({ name: 'quantity',  summary: 'SUM' })
        log.debug({title: 'Adjusting prebooked qty', details: 'New value = ' + prebookedQty})
        record.submitFields({
            type: record.Type.INVENTORY_ITEM,
            id: mums[i],
            values: { custitem_current_prebook_qty:  prebookedQty},
            options: {
                enableSourcing: false,
                ignoreMandatoryFields : true
            }
        })
    });
}
}
I'm thinking about using the UE to task a scheduled script to do the work posted above since that will add a bit of a delay. No idea if it will work consistently, or at all yet.
c
@Corey Schwoebel A couple of thoughts: one, you could explicitly filter out the internal ID of the record you're saving, then add 1 to the result count. This should reliably get the result count you need regardless of whether the sales order is new or not. Or you could try to add some random calculation as a formula search filter to help ensure that no search optimization is serving you cached results. Another note: does your company use multiple UOMs? If so, it might help to make sure you're converting and messaging the unit of measure this field is representing.