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
};
});

Maira S Beginner Asked on March 21, 2023 in SuiteScript.
Add Comment
10 Answers

Hi,

What is the type of custrecord_product?

Thanks,

Chris

Advanced Answered on March 21, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.