const afterSubmit = (scriptContext) => {
// grab the file from the file cabinet.
const folderSearchObj = search.create({
type: "folder",
filters:
[
["name","contains","Attachments"],
"AND",
["parent","anyof","[SOME_INTERNAL_ID]"]
],
columns:
[
search.createColumn({name: "internalid", join: "file", label: "Internal ID"})
]
});
const resultSet = folderSearchObj.run().getRange({
start: 0,
end: 1
});
const fileId = resultSet[0].getValue({
name: "internalid",
join: "file"
});
log.debug('fileId:', fileId);
const newRecordId = scriptContext.newRecord.id;
log.debug('new Record ID: ', newRecordId);
record.attach({
record: {
type: 'file',
id: fileId
},
to: {
type: record.Type.JOURNAL_ENTRY,
id: newRecordId
}
});
}
The resultSet is jank but it's for testing right now.
This is what I get when it runs:
{
type: "error.SuiteScriptError",
name: "RCRD_DSNT_EXIST",
message: "That record does not exist. id2: 7344035",
cause: {
type: "internal error",
code: "RCRD_DSNT_EXIST",
details: "That record does not exist. id2: 7344035",
],
notifyOff: false
},
notifyOff: false,
userFacing: true
}
Maybe I need to clear the cache because I was testing in the console with the variable called "id2"?