mg2017
02/22/2022, 11:23 PMconst file = file_search.run().getRange({
start: 0,
end: 10
}).forEach(getFiles);
try {
log.debug("Sending Email");
email.send({
author: 129272,
recipients: '<mailto:test@test.com|test@test.com>',
subject: "Note",
body: "Delivery Note Attached",
attachments: [file],
cc: null
});
} catch (e) {
log.error({title: 'Catch Block', details: e.toString()});
}
function getFiles(result) {
const file_internal_id = result.getValue({
name: 'internalid',
join: 'file'
});
log.debug({title: "File Internal ID", details: file_internal_id});
return true;
}
Why is this throwing TypeError: Cannot call method "hasOwnProperty" of undefined in my catch block?David B
02/22/2022, 11:31 PMtoString()
function on the error object must have a hasOwnProperty()
call on something that's undefined within the error object 😕
Not really an explanation of precisely why, but a solution would be to use JSON.stringify(e)
instead of e.toString()
mg2017
02/22/2022, 11:42 PMmg2017
02/22/2022, 11:58 PMforEach(getFiles);
log.debug({title: "File", details: file});
file is blank. How should I get the files using the forEach?Gerald Gillespie
02/23/2022, 12:06 AM...
catch({ message, stack}){
log.error({ title : 'something helpful', details : {message, stack}});
}
Gerald Gillespie
02/23/2022, 12:14 AMHow should I get the files using the forEach?to get just the contents you’ll need to
getContents()
it from file record. to get attributes of the file without loading full file include that in your search.
to attach it to an email as your code implies, you need file.File[]
array so you’ll have to use a method (e.g. file
(N/file) , render
(N/render) ) that returns that against your accumulated ids. probably for you file.load
Gerald Gillespie
02/23/2022, 12:29 AMforEach
was a typo? in each
loop accumulate ids or file.File records (by loading them) and then pass your accumulator to email.send
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_454656921386.htmlbattk
02/23/2022, 5:38 AMbattk
02/23/2022, 5:39 AMbattk
02/23/2022, 5:40 AMbattk
02/23/2022, 5:42 AMmg2017
02/23/2022, 5:37 PMfunction execute(context) {
var internal_id, file_obj, file_id, file_name, size;
const file_search = search.load({
id: 'customsearch_email_del_notes'
});
var file_count = file_search.runPaged().count;
log.debug({title: 'Number of files found', details: file_count});
file_search.run().each(function (result) {
file_id = result.getValue({
name: 'internalid',
join: 'file'
});
file_name = result.getValue({
name: 'name',
join: 'file'
});
file_obj = [];
file_obj.push(file.load({
id: file_id
}))
log.debug({title: "File Array Object", details: file_obj + " " + "Length:" + " " + file_obj.length});
return true;
});
try {
log.debug("Sending Email");
email.send({
author: 129272,
recipients: '<mailto:test@test.com|test@test.com>',
subject: "Delivery Note",
body: "Delivery Note Attached",
attachments: file_obj,
cc: null
});
} catch (e) {
log.error({title: 'Catch Block', details: e.JSON.stringify()});
}
}
Gerald Gillespie
02/23/2022, 7:14 PMfile_obj
is being reset to an empty array in every iteration. instead use your var
declaration to establish it a default value of []
and then each loop can push
to it.mg2017
02/23/2022, 8:46 PM