I have a scheduled script that is using a saved CS...
# suitescript
c
I have a scheduled script that is using a saved CSV import to import journal entries into NS. Stakeholder would like to attach a file in the file cabinet onto the JE once it's created from the import. I'm attempting to use an afterSubmit on a in a UE script to use the record.attach() method, but I'm getting a "record does not exist" when it's invoked. Does anyone have any recommendations how I can attach this file? Is the UE script the right approach to doing this or should I consider another scheduled script that triggers once the import is finished?
a
that sounds like the correct approach... what record "doesn't exist" ??? share your code?
c
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"?
a
are any of your logs triggered
hard to understand where its failing... and no idea where that id2 stuff is coming from thats weird
c
I think that's the issue. It's pulling an ID that doesn't exist from scriptContext.newRecord.id.
the ID is actually 7344335
a
oh 😞 well that's probably you're problem then
why would the record id change?
try moving your UE script to the last in the list on the script record page for JEs?
c
Ooooohhh good point, lemme try that.
a
yeah, code looks fine fwiw
sorry gtg do my actual job 😄 good luck
c
Haha no worries tysm for your help!