Attach pdf file from custom UI page upload button to Table record attachment.

Parul Singh
Tera Contributor

Hi ,

I have created one custom UI page having some input text fields(Name, Email ID) and one upload button which is used to upload one pdf file. Then when i click on the submit button a record should get created and the pdf file must be attached to the record on attachments internally.

 

function saveValues() {

  var jobDescription = document.getElementById("jobDescription").value;

  var hrEmailId = document.getElementById("hrEmailId").value;

  var recEmailId = document.getElementById("recEmailId").value;

  var fileInput = document.getElementById("resumeFile");

  var file = fileInput.files[0];

 

  alert("Job Description: " + jobDescription);

  alert("HR Email ID: " + hrEmailId);

  alert("Recuiter Email ID: " + recEmailId);

  alert("File Name: " + file.name);

 

  var grecord = new GlideRecord('u_candidate_resume_data_record');

  grecord.initialize();

  grecord.setValue('u_job_description', jobDescription);

  grecord.setValue('u_hr_email_id', hrEmailId);

  grecord.setValue('u_recruiter_email_id',recEmailId);

  var recordSysID = grecord.insert();

  alert("Record created with Sys ID: " + recordSysID);

 

  if (recordSysID && file) {

    var attachment = new GlideRecord('sys_attachment');

    attachment.initialize();

    attachment.setValue('table_name', 'u_candidate_resume_data_record');

    attachment.setValue('table_sys_id', recordSysID);

    attachment.setValue('file_name', file.name);

    attachment.setValue('content_type', file.type);

    alert("Now we will attach a file.");

    //attachment.file = file;

    attachment.setValue('file', file);

    //attachment.setStream('file', file.getInputStream());

    var attachmentSysID = attachment.insert();

    alert("Attachment created with Sys ID: " + attachmentSysID);

    gs.info("Attachment created with Sys ID: " + attachmentSysID);

  }

}

 

 

I am using this as my client script, in this pdf is getting attached but coming in 0 Bytes when downloading or seeing in sys_attachment table. I also used GlideSysattachment() function using another approach but its coming as not defined. Please help me with this ASAP. 

0 REPLIES 0