I'm refactoring a script that transforms an SO to ...
# suitescript
c
I'm refactoring a script that transforms an SO to an IF in an afterSubmit() on the SO. It was throwing an error saying there was no inventory detail on the lines in the IF so the IF could not be saved. I added this code
Copy code
soFulfillment.getCurrentSublistSubrecord({
    sublistId: 'item',
    fieldId: 'inventorydetail',
});
The resulting IF now has inventory details set on each of the fulfilled lines that matches the quantitycommited from the lines on the sales order. I thought I would have to set the quantity and status but the transform appears to be pulling those through automatically after adding the above code. I appreciate getCurrentSublistRecord actually adds the sublist record if not already present, I am surprised that the above code is enough to make the IF pull through the status and quantity though.
e
Interesting. Curious - in your code above, is the "soFulfillment" variable the Sales Order record or the new transformed Item Fulfillment record?
c
The new transformed IF
Copy code
const soFulfillment = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: so_ID,
    toType: record.Type.ITEM_FULFILLMENT,
    isDynamic: true
});
Copy code
const soFulfillment = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: so_ID,
    toType: record.Type.ITEM_FULFILLMENT,
    isDynamic: true
});

const lineCount = soFulfillment.getLineCount('item');

log.debug('lineCount', lineCount);

for (let i = 0; i < lineCount; i++) {

    soFulfillment.selectLine({
        sublistId: 'item',
        line: i
    });
    soFulfillment.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'itemreceive',
        value: true
    });

    soFulfillment.getCurrentSublistSubrecord({
        sublistId: 'item',
        fieldId: 'inventorydetail',
    });

    soFulfillment.commitLine({
        sublistId: 'item'
    });
}

soFulfillment.setValue('shipstatus', 'C');

const fulfillmentID = soFulfillment.save({
    ignoreMandatoryFields: true
})
The most interesting part of the script
e
I wonder if calling that method causes NS to reload the entire salesorder record again making it equivalent (from a performance standpoint) to calling record.load on the sales order within the afterSubmit. That is what I would have suspected you'd have to do in this case. For some Friday fun, you could test the two options and see if they are equivalent in speed. I looked to see how we do this transform but I forgot that we do it in a map/reduce so not a similar use-case.
c
There is no inventory detail on the SO either, it must be setting the status to a default and putting through the SO committedquantity line field.
👍 1
b
Hi! Have you sorted this out @Craig?
c
I did get an 'unexpected error' in prod that I'm looking into later but not clear if it's related or not. I am still curious why I don't have to set the date or status.
b
I have encountered an error transforming SO to IF before too but I can't recall the exact error I encountered, but my record.transform includes a default value of inventorylocation defaultValues: { inventorylocation: itemsArr[0].inventorylocation } where itemsArr is the list of items on the SO and I just pulled the first line's inventory location Then I think you can change it on the record.transform object
hope that helps
j
Just curious does the Accounting preference (Order Managaement / Fulfillment) play into this at all? Not super experienced scripting, but if I recall I was tripping over this setting.
c
@Jay Flynn09 that setting just checks or unchecks every item on the unsaved fulfillment - I wouldn't have though it would impact the inventory detail but NetSuite can be surprising.
1