Dealing with Attachments in Agile

Hi Everyone,

I am new to Agile. I am going to change the attachments of a list of stuff. I know we can change by doing manually. Can I ask if there is any convenient way, like using Agile API so I can code to solve this kind of question? What I need to do is to delete the original attachment and add new attachment.

Thank you in advance.

Add Comment
1 Answer(s)

Hi,

To Upload a new Attachment you can use the code below:

Map<Object, Object> map = new HashMap<Object, Object>();
map.put(CommonConstants.ATT_ATTACHMENTS_FILE_NAME, dto.fileName);
map.put(CommonConstants.ATT_ATTACHMENTS_CONTENT, dto.content);
map.put(CommonConstants.ATT_ATTACHMENTS_FILE_DESCRIPTION, dto.fileDescription);
IAttachmentRow) table.createRow(map);

public class AttachmentDTO {

public String fileName;
public String fileSize;
public String fileDescription;
public String fileType;
public String checkinUser;
public String modifiedDate;
public String attachmentType;
public InputStream content;
}

The following is to remove all attachments from a change (for example)

ITable attachmentsTable = change.getAttachments();
Iterator it = attachmentsTable.iterator();
List<IAttachmentRow> toBeDeleted = new ArrayList();

while (iterator.hasNext()) {
IAttachmentRow row = iterator.next();
//you cannot remove row from a table while iterating it
toBeDeleted.add(row);
}

for(IAttachmentRow currRow: toBeDeleted){
attachmentsTable.removeRow(currRow);
}

probably it doesn’t compile (I didn’t tried it but wrote directly) but this is just for an example. You can customize the code.

Agile Angel Answered on September 7, 2016.

Hi, thank you so much.

on September 12, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.