Hopefully someone has some experience with the inv...
# suitescript
c
Hopefully someone has some experience with the inventory detail on a Work Order Completion. I'm trying to script a WOC by transforming an existing Work Order, but running into issues with the inventorydetail field, particularly populating the inventoryassignment. I can set tobinnumber, toinventorystatus, and quantity, but I get USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Status (NOTE: in the UI, Serial/Lot Number does not appear in the Inventory Detail popup). If I try setting binnumber to the same value as tobinnumber -- or a completely different bin's internal ID -- I get INVALID_FLD_VALUE. Same for inventorystatus. I'm pretty confused at this point. Relevant code :
Copy code
/**
     * Sets the inventory detail for the Work Order Completion
     * 
     * @param {Object} woc Work Order Completion object in progress
     * @param {Float} quantity Quantity of assembly from build
     */
    function setInventoryDetail(woc, quantity) {
       
        log.debug({
            title : 'WOC',
            details : woc.inventorydetail
        });
        var invDetail = record.create({
            type : record.Type.INVENTORY_DETAIL,
            isDynamic : true
        });

        invDetail.setValue({
            fieldId : 'item',
            value : woc.getValue({ fieldId : 'item' })
        })
        .setValue({
            fieldId : 'location',
            value : woc.getValue({ fieldId : 'location' })
        })
        .setValue({
            fieldId : 'quantity',
            value : quantity
        });

        invDetail.selectNewLine({
            sublistId : 'inventoryassignment'
        });

        /*
        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'issueinventorynumber',
            value : ''
        });

        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'binnumber',
            value : ''
        });

        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'inventorystatus',
            value : ''
        });
        */

        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'tobinnumber',
            value : getBinId()
        });

        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'quantity',
            value : quantity
        });
        
        invDetail.setCurrentSublistValue({
            sublistId : 'inventoryassignment',
            fieldId : 'toinventorystatus',
            value : getStatusId()
        });

        log.debug({
            title : 'setInventoryDetail',
            details : 'Committing inventory assignment line'
        });

        invDetail.commitLine({
            sublistId : 'inventoryassignment'
        });

        log.debug({
            title : 'setInventoryDetail',
            details : 'Setting inventory detail on work order completion'
        });

        woc.setValue({
            fieldId : 'inventorydetail',
            value : invDetail
        });
    }
Thanks for any help you can provide!
m
Hi you need to set the binnumber before choosing a lot
Since your in dynamic mode, you will see in the UI, you cannot set the lot/serial before setting the binnumber
c
Thanks for replying! I don't have to even set a lot number in the UI (nor do I want to), but trying to set the binnumber field to a bin's internal ID gives me the INVALID_FLD_VALUE error. Using the same value to populate the tobinnumber field works.
This is in a Suitelet
b
i dont usually work with work order completions, but inventory details are usually subrecords
you use the subrecord related apis to manipulate them
c
@battk Thanks for the reply! I agree, but in the case of a work order completion it does not appear to be a subrecord (calling
hasSubrecord({ fieldId : 'inventorydetail' })
throws
FIELD_1_IS_NOT_A_SUBRECORD_FIELD
Just sort of a mystery why binnumber and inventorystatus won't take valid values, and the line item commit will not accept without those and Serial/Lot Number, which is not required in the UI.
e
I do this via a transform and using the
inventorydetail
subrecord.
Copy code
var workOrderCompRec = record.transform({
                fromType: record.Type.WORK_ORDER,
                fromId: workOrderId,
                toType: record.Type.WORK_ORDER_COMPLETION,
                isDynamic: false
            });
Copy code
var inventoryDetail = workOrderCompRec.getSubrecord({fieldId: 'inventorydetail'});
for (var j = 0; j < inventoryDetails.length; j++) {
	if (inventoryDetails[j].quantity) {		
		try {
			inventoryDetail.setSublistValue({
				sublistId: 'inventoryassignment',
				fieldId: 'quantity',
				value: inventoryDetails[j].quantity,
				line: j
			});
			inventoryDetail.setSublistValue({
				sublistId: 'inventoryassignment',
				fieldId: 'receiptinventorynumber',
				value: inventoryDetails[j].lotNumber,
				line: j
			});
		} catch (e) {			
			log.error('ERROR SETTING INV DETAIL', e);
		}
	}
}
💯 1
inventory details are my own objects from an external system
c
@ehcanadian Thank you so very much! I just now got around to testing using your logic and it worked perfectly!
👍 1
245 Views