Setting user id of an attachment
Posted: Mon Sep 21, 2015 4:54 pm
We have a script that generates a task of a new category from an existing task, and it moves file attachments from the original task to the new task, however since the upgrade from 4.0.19 to 5.0.5, the user associated with the task seems to randomly change. The random user is then added to the participants list of the new task and gets mailouts for each attachment and any future changes on the new task,
We are still using the older .bsh scripts, this is an excerpt fro the script that handles the moving of the attachments:
Even if the attachment user isn't randomly set, it seems to default to the user running the script, I'd like it to be the original user that uploaded the attachment. How can I do that?
We are still using the older .bsh scripts, this is an excerpt fro the script that handles the moving of the attachments:
- Code: Select all
/* Move any attachments */
if (task.hasAttachments()) {
int notCopied = 0;
Map ma = task.getAttachsTaskOrMessage();
Set s=ma.entrySet();
Iterator it=s.iterator();
while (it.hasNext()) {
Map.Entry m = (Map.Entry)it.next();
SecuredTaskAttachmentBean key = (SecuredTaskAttachmentBean)m.getKey();
boolean value = (boolean)m.getValue(); // True for Task attachment, False for Message attachment
int maxSize = Integer.parseInt(UDFManager.getTaskUDFValue(sc, configTaskId, "maxAttachmentCopySize"));
if (key.getSize() < maxSize*1024*1024) {
ByteArrayInputStream data = new ByteArrayInputStream(AttachmentManager.getAttachment(sc, key.getId()));
AttachmentManager.createAttachment( sc,
newTaskId,
null,
key.getUserId(),
key.getName(),
key.getDescription(),
data);
AttachmentManager.deleteAttachment( sc, key.getId());
} else {
notCopied++;
}
}
if (notCopied > 0) {
newMsgDesc = "There is one large file";
if (notCopied > 1) {
newMsgDesc = "There are " + Integer.toString(notCopied) + " large files";
}
newMsgDesc = newMsgDesc + " attached to the original report (#" + MyTaskNumber + ").";
MessageManager.createMessage(sc, newTaskId, newNoteId, newMsgDesc,
null, null, null, null, null, null, null, false);
}
}
Even if the attachment user isn't randomly set, it seems to default to the user running the script, I'd like it to be the original user that uploaded the attachment. How can I do that?