RE: getSublistValue is not returning value
I have used getSublistValue to get and set item’s internal id to other custom record’s “product” field. But its setting item name to “product” field instead of item id. Please Help!
/**
@NApiVersion 2.x
@NScriptType ScheduledScript
@NModuleScope SameAccount */
define([‘N/record’,’N/search’,’N/runtime’], function(record,search,runtime) {
function execute(context) {
try {
var script = runtime.getCurrentScript();
var id = script.getParameter({name: ‘custscript_qa_record_id’});
var type = script.getParameter({name: ‘custscript_qa_record_type’});
log.debug(‘i_qa_record_id:’, id+’,i_qa_record_type=’+type);
if(id && type)
{
var REC;
var quote = record.load({type: type, id: id});
log.debug(‘quote:==’,quote);
var customer = quote.getValue({fieldId: ‘entity’});
log.debug(‘customer:==’,customer);
var lineCount = quote.getLineCount({sublistId: ‘item’});
for(var cnt=0; cnt<lineCount; cnt++)
{
var i_quote = quote.getSublistValue({sublistId: ‘item’, fieldId: ‘custcol_far_trn_relatedasset’, line: cnt});
var item_1 = quote.getSublistValue({sublistId: ‘item’, fieldId: ‘item’, line: cnt});
log.debug(‘item_1===’,item_1);
if(i_quote)
{
REC.setValue({fieldId: ‘custrecord_products’, value:item_1 });
}//end of for(var cnt=0; cnt<lineCount; cnt++)
var i_id = quote.save({enableSourcing: true, ignoreMandatoryFields: true});
log.debug(‘i_id:=== ‘+i_id);
}//end of if(id && type)
}catch (error) {
log.debug(‘Error’, error);
}
}
return {
execute: execute
};
});
Hi Maira,
You are loading a quote but you are not creating your custom record on which you are setting a value. You are saving the quote (but you do not set any value on it, so no need to save it) but not your custom record. So your script is not doing anything at that point.