Service Desk Practitioners Forum
cancel
Showing results for 
Search instead for 
Did you mean: 

attachment in servicepages

Highlighted
Zahir_3
Super Collector

attachment in servicepages

Hi,

could you any one help me how to have attachment option enabled in service pages?

I am using SD 4.5 with SP7. Application and service pages webcomponent installed on 2 different server.

Zahir
9 REPLIES
Gyula Matics_1
Honored Contributor

Re: attachment in servicepages

Attachments are not supported in service pages.

It is possible to add support for it, but it means coding your own file upload service.
Zahir_3
Super Collector

Re: attachment in servicepages

some people could have already done similar work it seems..it would be fine if they share with me.
Gyula Matics_1
Honored Contributor

Re: attachment in servicepages

Yes, I've did it more than once. But each time it is different, because of the different requirements.

In the simplest case it can be hacked together from two examples. Here is the outline how to do it.

1. download the apache commons fileupload class.
http://jakarta.apache.org/commons/fileupload/
2. read the users guide for a 5 lne example on how to use fileupload, and add that code to the service pages.
http://jakarta.apache.org/commons/fileupload/using.html
3. then, in your code, save the resulting file in a temporary directory.
4. read Example9.java on how to attach the file to a service call or other object.

That's it.
Gyula Matics_1
Honored Contributor

Re: attachment in servicepages

your code handling the file will look like someting like this. This is code is probably not working as is. I've cut&pasted it from a project but deleted some unrealated part of it.

IAttachedItemHome aHome = session.getAttachedItemHome();
IEntityInfoHome entInfHome = bean.sd_session().getEntityInfoHome();
IEntityInfo entInfo = entInfHome.openEntityInfo(sc.getItemType());
IAttachment att = sc.getAttachment();
att.setAttachmentExists(new Boolean(true));



String cFileDir = "C:\\temp\\";
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("utf-8");
List list = upload.parseRequest(request);
Iterator iterator = list.iterator();

while(iterator.hasNext()) {
FileItem fileItem = (FileItem)(iterator.next());

if(!fileItem.isFormField()) {
String cFileName = new String (fileItem.getName().getBytes(),"utf-8");

if(cFileName.length()>1) {
File file = new File(cFileDir, cFileName);
fileItem.write(file);

IAttachedItem nItem = aHome.openNewAttachedItem();
nItem.setFilename(cFileDir + cFileName);
nItem.setBaseName(cFileName);
nItem.setParentEntityType(entInfo);
att.addAttachedItem(nItem);

}
}
}
att.transfer();
sc.save()
Zahir_3
Super Collector

Re: attachment in servicepages

Thanks.

There was a code sent by someone before same like this. It was working fine if both application server and service pages installed on the same machine.

In my case, application server and services pages are installed on 2 different machines so that it was not working.

How is your schenorio?

Do I have to do any special configuration for my setup?

Pls. let me know.

Gyula Matics_1
Honored Contributor

Re: attachment in servicepages

The web-api requires that the file be accessible for the server. So yes, you need an application server on the machine running service pages. Is there a reason you can't install a local server? I know that it is sometimes not possbile, but in most cases this is the simplest solustion.
Zahir_3
Super Collector

Re: attachment in servicepages

Our users are accessing servicepages through internet. In order to secure our environment, we have splitted the service pages and application server on two different machine and there is a firewall between servicepages and application server.



Gyula Matics_1
Honored Contributor

Re: attachment in servicepages

In that case, you have no choice but find a way to transfer the attached file to a temporary location on the application server. Probably copying it with ssh or https will be safe and simple enough to work via the firewall.
Zahir_3
Super Collector

Re: attachment in servicepages

In this case I have to FTP/SSH the files from some directory in service pages server to some directory in application server either manually or scheduled manner then attach those files with the specific service calls manually.

Is there anyway how can automatically link the files to the specific call ID once the files reaches to application server from service pages.
//Add this to "OnDomLoad" event