I created a scheduled script that uploads journals...
# ask-stanley-ai
c
I created a scheduled script that uploads journals through a saved csv import, but I have to attach a file to a sublist field on the journals after they've been created. How do I attach these files after the import has finished running?
c
AI generated answer (using internal Slack threads):
To attach files to a sublist field on the journals after they've been created, you can use SuiteScript. Here's a general approach: 1. After the CSV import is finished, you can call a scheduled script. This script will be responsible for attaching the files to the journals. 2. In the scheduled script, you will need to search for the journals that were just created. You can do this by filtering on the creation date or any other unique identifier that was included in the CSV import. 3. Once you have the journals, you can then search for the files that need to be attached. This can be done by searching the file cabinet using the
N/file
module. 4. After you have both the journals and the files, you can then attach the files to the journals. This can be done using the
record.attach
method in SuiteScript. Here's a pseudo code example:
Copy code
javascript
var file = file.load({
    id: 'fileId'
});

var attachOptions = {
    record: {
        type: 'journalentry',
        id: 'journalId'
    },
    file: file
};

record.attach(attachOptions);
In this example, replace
'fileId'
with the ID of the file you want to attach and
'journalId'
with the ID of the journal to which you want to attach the file. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830349922
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826232493
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.823935628
Please provide your feedback on this answer.
c
but how do I check that the csv import task is finished? How do I wait for that through script?