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

Move attachments from Service Call to Problem?

Go to solution
Tyler van Vierz
Acclaimed Contributor

Move attachments from Service Call to Problem?

Greetings all -- first of all THANK YOU for all the amazing advice and info contained in this forum. I spent a Monday getting to know the web api and everytime I ran into confusion, this forum got me coding again.

My question: I wrote code, based on the example code and advice found here, to (from the command line) take multiple Service Calls, create a Problem, relate the given SCs, and move all the SC attachments to the PR. All of it works, EXCEPT the part to move the attachments. They appear to move, and they show up on the Problem, but when I click on them, I get an FTP error (GIF attached). (Apparently you can't copy 'em either -- they remove themselves from the SC -- so now they're broken/lost completely on my test records.)

I'll warn you that I've never worked in Java but figured I'd use it for this. So I'm sure this is ugly. It was exploratory code. :)

Background: "SCIDS" is an ArrayList of the Service Call ID numbers specified on the command line.

Here's the snippet that did the attachments:

// removed as it was moving the icon but an FTP error occurred and they could not
// be opened!!
// Move attachments from all specified SCs to the PR
IAttachment prAttachments = problem.getAttachment();

i = 0;
int j = 0;
IServicecall aTmpSC = null;
String aTmpStr = null;
for (i=0; i < SCIDS.size(); i++)
aTmpStr = (String) SCIDS.get(i);
aTmpSC = scHome.openServicecall(Long.valueOf(aTmpStr).longValue());

IAttachment scAttachments = aTmpSC.getAttachment();
// java.lang.Boolean bTmp = scAttachments.getAttachmentExists();

// if (bTmp.booleanValue())
// {
IAttachedItem[] items = scAttachments.getAttachedItems();
if (items.length > 0)
System.out.println("Found " + items.length + " attachment(s) in Service Call " + aTmpStr + ".");
for ( j=0; j prAttachments.addAttachedItem(items[j]);
System.out.println("Attachment moved.");
System.out.println("Attachments transfered (notified parent object of change).");
} else {
System.out.println("No attachments found in Service Call " + aTmpStr + ".");
Gyula Matics_1
Honored Contributor

Re: Move attachments from Service Call to Problem?

Is see only one minor problem with your code: you need to set the parent object type on the attachment record. (see Example9).

Also, if you comment the line scAttachments.setAttachmentExists(java.lang.Boolean.FALSE);
then you'll see if they are really moved. Attachmentexists just controls the client if it will show the attachments.

But the actual problem is, that SD will not move the physical files. Pre-SP16 the files are in a structure like the following:

So, you'll have to move the files yourself, from the Servicecall/ folder to Problem/.

SP16 and later are using a more complex structure.
//Add this to "OnDomLoad" event