Attaching a File to a New Job in Script
4 min
overview you can attach a file to a job before submitting it by creating a jobattachment from a file stream and adding it to the job's attachment collection use case use this approach when a script needs to create a new job and include one or more file attachments as part of the submission example using system io; job j = new job(); j task = evaluator getobject("=//tasks/log a call") as task; string filepath = @"c \temp\myreport csv"; byte\[] file = file readallbytes(filepath); using (memorystream ms = new memorystream(file)) { jobattachment ja = jobattachment create( "activateextract csv", "application/text", file length, ms ); j attachments add(ja); j submit(); } how it works create a new job object assign a task to the job read the file into a byte array create a memorystream from the file contents create a jobattachment using the stream add the attachment to the job submit the job key points jobattachment create() creates an attachment from a stream the attachment must be added to the job's attachments collection before submission a task must be assigned to the job before calling submit() the attachment filename does not need to match the source file name the mime type should reflect the file being attached notes the example uses a memorystream to provide the attachment content ensure the file exists and is accessible before attempting to read it consider adding error handling to manage missing files, access issues, or submission failures