Uploading attachment in customer portal

For various reasons I need to make a customized new ticket screen in customer portal. I'm making it as a ejScript and using embedded ejscript code.

I've added a file upload element like the standard screen but I don't understand how to create the attachment. When I press the add-button I get the filename and location of the file but how do I upload it?

/ Peter

Re: Uploading attachment in customer portal

Hi Peter.

To get file attachments to work in an ejScript, you need two things:

1) Use enctype="multipart/form-data" in the form element
2) Use the function saveCgiAttachment with the name as parameter.

By: Hans Oluf Waaler 19 Apr 2011

Re: Uploading attachment in customer portal

Thanks for quick reply.

1. Like this?

<form method='post'  enctype='multipart/form-data' action='/bin/customer.exe?action=safeParse&includeId=hsbNewTicket&key=86MuKuM8ZDQfSkEW&withFrame=1'>

2. What name should I put in as parameter? The name of the html element? file name?

/ Peter

By: Peter Borg 19 Apr 2011

Re: Uploading attachment in customer portal

1. Yes (it worked)

2. It's the html name

/ Peter

 

By: Peter Borg 19 Apr 2011

Re: Uploading attachment in customer portal

Hello

Can you explain more when you say it's the html name you send as parameter in saveCgiAttachment()? I tried with the name, but it didn't work. 

I have also a problem when there are two attachments. When I use getParserVariable("attachments") I get the ids for all attachment added. But how do I get the name,contenttype  etc for all attachments?

Thanks!

By: Frode Follerås 30 Aug 2011

Re: Uploading attachment in customer portal

Hi Frode.

When you in HTML add an input of the type file, (for attachments), you typically write something as:
<input type="file" name="attachment" />

The name attribute is what I mean with HTML name (and not for instance the id attribute).

To get the name and contentType, you need to open the attachment by id with the object Attachment, and then you can retrieve the name and contenttype from this.

For instance:
String[] attachments = getParserVariable("attachments").split(",");
for (Integer i=0;i<attachments.length(); i++)
{
  Attachment att;
  att.load( attachments[i].toInteger() );
  String contentType = att.getValue("contentType");
  String name = att.getValue("name");

  // Use the values to display in a grid/table or something

}

By: Hans Oluf Waaler 31 Aug 2011

Re: Uploading attachment in customer portal

Thanks for the answer. It worked for displaying the table with attachments. But the attachments are not saved inn the case that's created. I use

 

By: Frode Follerås 5 Sep 2011

Re: Uploading attachment in customer portal

Hi!

Yes, the saveCgiAttachment only saves the files. It does not connect them to a request. Actually, the attachments are not connected to the request itself, but one of its messages.

What you need to do, is to run setAttachments on the message object. The setAttachments method takes a vector as an argument. You can use the method parseString on the vector object to populate the vector.

One important note here is that setAttachments method must be called AFTER you have saved the message (the message must exist in the database).

 


By: Hans Oluf Waaler 5 Sep 2011