ВНИМАНИЕ! Скрипт работает только в случае одного исполнителя!
Скрипт выставляет галки “Доступ к карточке-основанию”, “Не требует подтверждения выполнения”, копирует вложения из документа в задачу и текст из поля “Содержание” документа в поле “Полное описание” задачи.

Скрипт
// task
import com.haulmont.cuba.core.EntityManager
import com.haulmont.cuba.core.Persistence
import com.haulmont.cuba.core.Transaction
import com.haulmont.cuba.core.entity.FileDescriptor
import com.haulmont.cuba.core.global.*
import com.haulmont.thesis.core.entity.Task
import com.haulmont.workflow.core.app.WfService
import com.haulmont.workflow.core.entity.Assignment
import com.haulmont.workflow.core.entity.AttachmentType
import com.haulmont.workflow.core.entity.Card
import com.haulmont.workflow.core.entity.CardAttachment
import com.haulmont.workflow.core.global.AssignmentInfo
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang.StringUtils
import org.apache.commons.lang.exception.ExceptionUtils
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
Log log = LogFactory.getLog(Scripting.class);
Transaction tx = AppBeans.get(Persistence.class).getTransaction();
try {
EntityManager em = AppBeans.get(Persistence.class).getEntityManager();
UUID taskId = task.getId();
Task reloadedTask = em.find(Task.class, taskId);
if (reloadedTask != null) {
copyAttachmentsToTask(card, reloadedTask);
setTaskFullDescription(card, reloadedTask);
reloadedTask.setParentCardAccess(true);
reloadedTask.setConfirmRequired(true);
}
tx.commit();
} catch (Exception ex) {
log.error(ExceptionUtils.getStackTrace(ex));
} finally {
tx.end();
}
void copyAttachmentsToTask(Card card, Task task) {
if (card == null || task == null)
return;
UserSessionSource UserSessionSource = AppBeans.get(UserSessionSource.class);
TimeSource timeSource = AppBeans.get(TimeSource.class);
Metadata metadata = AppBeans.get(Metadata.class);
EntityManager em = AppBeans.get(Persistence.class).getEntityManager();
List<CardAttachment> newAttachments = new ArrayList<>();
if (CollectionUtils.isNotEmpty(card.getAttachments())) {
for (CardAttachment srcAttachment : card.getAttachments()) {
if (srcAttachment.getVersionOf() == null) {
CardAttachment newAttachment = metadata.create(CardAttachment.class);
newAttachment.setName(srcAttachment.getName());
newAttachment.setCreatedBy(UserSessionSource.getUserSession().getCurrentOrSubstitutedUser().getLogin());
newAttachment.setSubstitutedCreator(UserSessionSource.getUserSession().getCurrentOrSubstitutedUser());
newAttachment.setCreateTs(timeSource.currentTimestamp());
newAttachment.setComment(srcAttachment.getComment());
newAttachment.setVersionNum(srcAttachment.getVersionNum());
newAttachment.setCard(task);
if (srcAttachment.getAttachType() != null) {
AttachmentType type = em.find(srcAttachment.getAttachType().getClass(), srcAttachment.getAttachType().getId());
newAttachment.setAttachType(type);
}
if (srcAttachment.getFile() != null) {
FileDescriptor fileDescriptor = em.find(srcAttachment.getFile().getClass(), srcAttachment.getFile().getId());
newAttachment.setFile(fileDescriptor);
}
em.persist(newAttachment);
newAttachments.add(newAttachment);
}
}
task.setAttachments(newAttachments);
}
}
void setTaskFullDescription(Card card, Task task) {
EntityManager em = AppBeans.get(Persistence.class).getEntityManager();
WfService wfService = AppBeans.get(WfService.NAME);
Set<AssignmentInfo> assignmentInfos = wfService.getAssignmentInfos(card);
if (assignmentInfos.iterator().hasNext()) {
AssignmentInfo assignmentInfo = assignmentInfos.iterator().next();
UUID assignmentId = assignmentInfo.getAssignmentId();
Assignment assignment = em.find(Assignment.class, assignmentId);
if (assignment != null) {
String comment = assignment.getComment();
if (comment != null && !StringUtils.EMPTY.equals(comment)) {
task.setFullDescr(comment);
}
}
}
}