Hello !
I am trying to copy the content of the Descriptions line of a SO, with the descriptions lines of the PO that generated this SO. : The creation of the SO is done through the function "manage intercompany Sales order", works fine, but let the Description fields lines in blank.
There is a solution proposed in SuiteAnwsers :
https://suiteanswers.custhelp.com/app/answers/detail/a_id/50012/loc/en_US
This solution is to use a Script.
I have installed the Script, and although the SuiteScript 1.0 works fine, I want to use the SuiteScript 2.0
I have copyed/pasted the code, all is ok. When I Edit an SO generated from a PO, I get the error message :
TypeError Cannot read properties of undefined (reading 'getValue'); ID:
|
|---|
|
I copy paste the script given in suite anwser below :
The problem seems to be on the "var poID = …" line. But I can't get to fix it.
Any help ?
function pageInit(scriptContext) {
var poID = scriptContext.currentRecord.getValue({
fieldId: 'intercotransaction'
})
if (poID != '') {
var rec = record.load({
type: record.Type.PURCHASE_ORDER,
id: poID,
isDynamic: true,
})
log.debug('Purchase Order', poID)
var itemCount = rec.getLineCount({
sublistId: 'item'
});
log.debug('Purchase Order', itemCount)
for (var i = 0; i <= itemCount; i++) {
rec.selectLine({
sublistId: 'item',
line: i
});
var description = rec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'description'
});
log.debug('description', description)
scriptContext.currentRecord.selectLine({
sublistId: 'item',
line: i
});
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'description',
value: description
})
scriptContext.currentRecord.commitLine({
sublistId: 'item'
});
}
}
}