Hey all. I'm trying to find a way to find to retri...
# suitescript
t
Hey all. I'm trying to find a way to find to retrieve the Work Order number that is attached to a Line Item on a Sales Order in the {createwo} field. However, when I use rec.getSublistValue(), it only returns a true/false value. Does anyone know of an easy way to retrieve the Work Order number from this field?
a
This is not possible, I remember building an script to handle the work order creation in a custom way. If I remember correctly you should be able to do a reverse search, meaning searching from work orders and exposing the created from and you will have/get the Sales Order.
t
Thanks @alien4u
e
I use getSublistText() which returns the WO
internalid
and then I lookup the tranid
👍 1
Copy code
for (var i = 0; i < lineCount; i++) {
	var woNumber = salesOrder.getSublistText({
		sublistId: 'item',
		fieldId: 'woid',
		line: i
	});
	if (woNumber) {
		var fieldLookup = search.lookupFields({
			type: search.Type.WORK_ORDER,
			id: woNumber,
			columns: 'tranid'
		});
		log.debug('WO INFO', 'Line: ' + i + ' Sales order: ' + recordId + ' wo number: ' + woNumber + ' tranid: ' + fieldLookup.tranid);
	}
}
v
Be careful with making searches inside the loop. If you have over 100 lines your script will crash with ScriptExecution limit.
n
better to scoop up all line details and perform one search rather than a lookup per line I'd suggest.
e
Eek, yeah, I should fix that