We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

Uploading file to case using script

Hello,

 

we have created a webform on our customer-pages that generates a ticket with an attached csv containing the information that was entered by the customer.
This is working as expected. We also wish to allow the customer to upload their own csv/excel file that is then attached as an aditional attachment in the ticket. This we are not able to to.


We have the following in our html-script:

<div id='fileList'>
    <h4>Last opp FI-tabell </h4>
    <input type="file" name="attachment_[]" id='newFiles' multiple />
    <input type="hidden" name="attList" id="attList" value="" >
</div>

which is inside:

<form method="post" name="mainForm" enctype="multipart/form-data" action="%AuthProgram%&withFrame=1&action=safeParse&includeId=bestillingskjema_post&key=****">

This looks ok, and the customers are seemingly able to upload files here. 

In our SO-script we have:

Vector vIds;
Attachment att;
att.load(getParserVariable("attachment_[]").toInteger());
att.setValue("name","fi.csv");
Integer atId = att.save();
vIds.pushBack(atId.toString());*/   
    
Byte[] byteContent = csv.toByteArray();
String base64 = encodeBase64(byteContent);
Attachment a;
a.setValue("name","bestillingsskjema.csv");
Integer attId = a.save();
Integer size = a.saveBase64(base64);
vIds.pushBack(attId.toString());

vIds attached to a message later in the script. 



The bottom half of this is a csv generated earlier in the script from the informaiton the user inputs. This works as expected. 
The former part seemingly generates a csv, but cannot be opened. 

For the upper half I have tried replacing "attachment_[]" with "attList", and I have also tried the following: 

Vector vIds;
String[] attachments = getParserVariable("attList").split(",");
for (Integer i=0;i<attachments.length(); i++)
{
  Attachment att;
  att.load( attachments[i].toInteger() );
  att.setValue("name","fi.csv");
  Integer atId = att.save();
  vIds.pushBack(atId.toString());
}

In this case, no file is generated at all. 

It seems obvious that I am missing something, but cannot figure out what.



Any help or input is much appreciated! We are ready for deployment of the form, but are missing this last part. 

 

Regards, 

Rikke Mohn

RE: Uploading file to case using script

Hi,

Would expect that this should work;

Vector vIds = Vector(saveAllCgiAttachments("attachment_[]"));
Av: Michel Krohn-Dale 1. jul 2020