```function validateLine(context) { let cu...
# suitescript
w
Copy code
function validateLine(context) {
        let currentRecord = context.currentRecord;
        let sublistId = context.sublistId;
        if (sublistId === 'item') {
            let inventoryDetail = getInventoryDetail(context);
            }
        }
    }
	
function getInventoryDetail(context) {
        let currentRecord = context.currentRecord;
        let details = [];
        let inventoryDetail = currentRecord.getCurrentSublistSubrecord({
            sublistId: 'item',
            fieldId: 'inventorydetail'
        });
        if (inventoryDetail) {
            let count = inventoryDetail.getLineCount({
                sublistId: 'inventoryassignment'
            });
            for (let i=0; i<count; i++) {
                inventoryDetail.selectLine({
                    sublistId: 'inventoryassignment',
                    line:       i
                });
                let id=inventoryDetail.getCurrentSublistValue({
                    sublistId:  'inventoryassignment',
                    fieldId:    'inventorydetail'
                });
                log.debug({
                    title: 'getInventoryDetail inventoryassignment line ' + count,
                    details:    id		//returns id = 77393 in logs, but the UI indicates 91867
                });
                let inventoryNumberRecord = record.load({
                    type:   record.Type.INVENTORY_NUMBER,
                    id:     id
                });
				//Causes an error - RECORD DOES NOT EXIST
                log.debug({
                    title:  'inventoryNumberRecord',
                    details: JSON.stringify(inventoryNumberRecord)
                })
                let inventoryNumber = search.lookupFields({
                    type:   search.Type.INVENTORY_NUMBER,
                    id:     id,
                    columns:    ['inventorynumber']
                });
                if (inventoryNumber) {
                    details.push(inventoryNumber);
                }
            }
        }
        return details;
    }
I'm trying to use validateLine on a client script in the purchase order record to retrieve the inventory detail for the current line.
The logs show the id of inventorydetail as 77393, but the UI says 91867. What am I doing wrong?
a
umm not related to your issue, but you validate line function needs to return true/false
b
the inventory detail subrecord and the inventory number record are different records
w
@battk Thanks, I'll do some more digging into which to use.
@Anthony OConnor validateLine may turn out to not be the right fit for this
m
The sublist id is good ?
Do you have Netsuite field explorer ?if yes search what is 77393
w
@Marc Installed NS Field Explorer, but how do you use it for inventory detail fields?
m
Your screenshot is on the record ?
w
on the PO record
m
When you launch field explorer , you have nothing with 77393 ? And with 91867?
b
you arent gonna have much luck with subrecords using the field explorer
you need to actually know how to inspect records
your choices are to use the suitescript debugger to inspect the inventory details subrecord
logging the subrecord in the script exeuction logs
or logging the subrecord in the console browser, which requires you to manually use .toJSON on the subrecord before logging
2
w
I think this is not going to work with a client script, it will have to be done server side