setSublistValue – cannot get the record to update

Hello –

I am running a search of item receipt, creating a custom record  and I want to update the line item from the item receipt.   Some of this is in here to ensure that I know where the fail is … (getSublistValue works on line 0).   I would like to derive the line from the search, however, for testing I was hard coding the line.  The test item receipt has a single item in it – so two line transaction  – so line 1 #should# work?     The fail happens on the last execution for setSublistValue.

Any ideas on why it is failing? Thanks in advance!

 

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/

define([‘N/file’, ‘N/search’, ‘N/record’],

function(file, search, record) {
function execute(scriptContext) {

var itemreceiptSearchObj = search.create({
type: “itemreceipt”,
filters:
[
[“type”,”anyof”,”ItemRcpt”],
“AND”,
[“mainline”,”is”,”F”],
“AND”,
[“item.type”,”anyof”,”InvtPart”],
“AND”,
[“createdfrom.type”,”anyof”,”PurchOrd”],
“AND”,
[“appliedtotransaction”,”noneof”,”@NONE@”],
“AND”,
[“appliedtotransaction.custbodyconsignedpo”,”is”,”T”],
“AND”,
[“item.custitemmedium”,”noneof”,”94″,”95″],
“AND”,
[“createdfrom.status”,”noneof”,”PurchOrd:G”],
“AND”,
[“trandate”,”onorafter”,”daysago40″]
],
columns:
[
search.createColumn({
name: “internalid”,
join: “appliedToTransaction”
}),
search.createColumn({name: “line”}),
search.createColumn({
name: “itemid”,
join: “item”,
}),
search.createColumn({
name: “formulatext”,
formula: “CONCAT(CONCAT(SUBSTR({item.name},INSTR({item.name},’:’)+2),’-‘),{serialnumbers})”
}),
search.createColumn({
name: “formulatext_1”,
formula: “CONCAT({appliedtotransaction},”)”
}),
search.createColumn({
name: “internalid”,
join: “item”
}),
search.createColumn({
name: “formulatext_2”,
formula: “SUBSTR({item.name},INSTR({item.name},’:’)+2)”
}),
“serialnumbers”,
search.createColumn({
name: “formulatext_3”,
formula: “Concat({appliedtotransaction.line},”)”
}),
search.createColumn({
name: “formulatext_4”,
formula: “CONCAT({appliedtotransaction.custcolconsigned},”)”
}),
“trandate”,
search.createColumn({
name: “custitemnumbereditionconsigned”,
join: “itemNumber”
}),
search.createColumn({
name: “custcoltranconsignmenttracker”
}),
“appliedtotransaction”,
“amount”
]
});

var searchResult = itemreceiptSearchObj.run().getRange({
start: 0,
end: 10
});

log.debug(‘searchResult’, searchResult);

searchResult.forEach(function(result) {

var receiptid = result.id;
var receiptline = result.getValue(‘line’);
var CTName = result.getValue(‘formulatext’);
var CTItem = result.getValue({join:’item’, name:’internalid’});
var CTPO = result.getValue(‘appliedtotransaction’);
var CTEdition = result.getValue(‘serialnumbers’);

log.debug(‘Receipt’, receiptid);
log.debug(‘Receipt Line’, receiptline);
log.debug(‘item’, CTItem);
log.debug(‘ediiton’, CTEdition);

var Consign = record.create({
type: ‘CUSTOMRECORDCONSIGNMENTTRACKER’,
});

Consign.setValue(‘name’, CTName);
Consign.setValue(‘custrecordconsignmentitem’, CTItem);
Consign.setValue(‘custrecordconsignmentpurchaseorder’, CTPO);
Consign.setText(‘custrecordconsignmentserial’, CTEdition);
Consign.setValue(‘custrecordctinventorystatus’, 1);
Consign.setValue(‘custrecordctitemreceipt’,receiptid)

var NewCTrecord = Consign.save();

log.debug(‘newrecord’, NewCTrecord);

var CTReceipt = record.load({
type: record.Type.ITEM_RECEIPT,
id: receiptid,
isDynamic: false
});

var location = CTReceipt.getSublistText({
sublistId: ‘item’,
fieldId: ‘location’,
line: 0
});

log.debug(location);

var newct = CTReceipt.setSublistValue({
sublistId: ‘item’,
fieldId: ‘custcoltranconsignmenttracker’,
line: 1,
value: NewCTrecord
});

});

 

};
return {
execute: execute
};

});

Rookie Asked on March 9, 2023 in SuiteScript.
Add Comment
1 Answer(s)

I think you need to commit the line after setting the value on the sublist.

Rookie Answered on March 13, 2023.

thank you! that was it!

on March 16, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor