Netsuite Tragic
03/05/2021, 3:29 AMfor ( var key in newRecord ) {
if (newRecord.hasOwnProperty(key)) {
log.debug('key:'+key,' value:'+newRecord[key])
newRecord.getValue({
fieldId: key,
value: [key]
});
}
}
This steps through the keys of the objects like key:findMatrixSublistLineWithValue but I want to access my field. Thoughts appreciated.battk
03/05/2021, 3:32 AMbattk
03/05/2021, 3:33 AMbattk
03/05/2021, 3:34 AMbattk
03/05/2021, 3:35 AMNetsuite Tragic
03/05/2021, 4:08 AMstalbert
03/05/2021, 4:19 AMtoJSON()
for records is undocumented - I wouldn't dare write any code that relies on its output.stalbert
03/05/2021, 4:46 AMconst values = newRecord.getFields()
.filter( name=> name.startsWith('custrecord'))
.map( name=> newRecord.getValue({fieldId:name}))
Netsuite Tragic
03/05/2021, 4:47 AMfor ( var key in allFields ) {
if (allFields.hasOwnProperty(key)) {
if(JSON.stringify(allFields[key]).indexOf('custrecord')>-1){
var valField = newRecord.getValue({
fieldId: allFields[key]
});
log.debug('name:'+allFields[key]+' value : '+valField);
}
}
}
i'll try @stalbert code also.stalbert
03/05/2021, 4:49 AMfor..in
and use of .hasOwnProperty
as that would be redundant. In other words, you should be able to skip the if(allFields.hasOwnProperty()
part.stalbert
03/05/2021, 4:50 AMstalbert
03/05/2021, 4:51 AMconst values = newRecord.getFields()
.filter( name=> name.startsWith('custrecord'))
.map( name=> ({ name, value: newRecord.getValue({fieldId:name})}))
battk
03/05/2021, 4:54 AMstalbert
03/05/2021, 4:55 AMbattk
03/05/2021, 4:55 AMNetsuite Tragic
03/05/2021, 4:56 AMstalbert
03/05/2021, 4:57 AMrecord.getValue({ fieldId: 'custrecord_inspection_lights')
- i.e. just use the field names without getting fancy unless you really need to.battk
03/05/2021, 4:57 AMbattk
03/05/2021, 4:58 AMfor (var i = 0; i < allFieldsl.length;i++)
battk
03/05/2021, 4:58 AMstalbert
03/05/2021, 5:01 AMfor...of
not for...in
. That distinction is one reason I tend to avoid for
loops altogether and write things in a more functional style where the chained method names have actual meaning. 🙂Netsuite Tragic
03/05/2021, 5:05 AMstalbert
03/05/2021, 5:07 AMbattk
03/05/2021, 5:17 AM