Hello,
I am trying to implement a mass update script to only add image alt content on an item's associated image if there is no value.
/**
* @NApiVersion 2.1
* @NScriptType MassUpdateScript
*/
define(['N/record', 'N/log'], (record, log) => {
const update = (context) => {
try {
// Load the Item Record
const itemRec = record.load({
type: context.type,
id: context.id,
isDynamic: true
});
// Get Store Display Name
const storeDisplayName = itemRec.getValue({ fieldId: 'storedisplayname' }).replace(/[&<>'"\/,]/g, '') || '';
const lineCount = itemRec.getLineCount({ sublistId: 'itemimages' });
if (lineCount > 0) {
for (let i = 0; i < lineCount; i++) {
const altTagCaption = itemRec.getSublistValue({
sublistId: 'itemimages',
fieldId: 'altTagCaption',
line: i
});
if (!altTagCaption) {
itemRec.setSublistValue({
sublistId: 'itemimages',
fieldId: 'altTagCaption',
line: i,
value: storeDisplayName
});
log.audit('Alt Tag Updated', `Line ${i} - New Alt Tag: ${storeDisplayName}`);
}
}
itemRec.save();
}
} catch (e) {
log.error('Error Updating Alt Tag', e.toString());
}
};
return {
each: update
};
});
The only error I get is
TypeError: Cannot read property 'replace' of undefined
|
|---|
|
When I do remove that piece of the const, no updates are made. Am I missing anything to this? or do I need to run certain criteria first?