Hello gurus!
I think this should be simple but struggling to find the right code for this this. I have a custom List field on my Item record and want to get the value when the Item is entered on a sales order.
My Script:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/error', 'N/record', 'N/search', 'N/email'], function(error, record, search, email) {
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
var line = context.line;
if (sublistName === 'item' && sublistFieldName === 'item') {
var itemId = currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: sublistFieldName
});
log.debug('itemId', itemId);
var itemSubclass = search.lookupFields({
type: 'assemblyitem',
id: itemId,
columns: ['custitem_cry_sales_subclass']
});
var itemSubclassData = itemSubclass['custitem_cry_sales_subclass'];
log.debug('itemSubclassData', itemSubclassData);
var itemSubclassText = itemSubclassData['text'];
log.debug('itemSubclassText', itemSubclassText);
}
}
}
return {
fieldChanged: fieldChanged
};
});
Output for itemSubclass looks like this:
{"custitem_cry_sales_subclass":[{"value":"4","text":"DX"}]}
I'm trying to get the text value "DX" but not sure how to parse this data.
Output for itemSubclassData looks like this:
[{"value":"4","text":"DX"}]
I was trying to remove the [] with a replace method but get an error on that, I think because it's not a true text string.
I also tried some variations of JSON parsing but no luck there either. Another option would be to load the item record and then get the field and value, but I was hoping not to have to do that.
Anyone know the best way to parse out the data here?
Thanks!
Judy