How to add a document as both work item attachment and case document
Sometime, when add an attachment from your local desktop, you may want
to also add the attachment document as case document. This function can
be implemented by replacing the attachment page widget's 'Add Document
From Local System' action button by an event action and a script
adapter.
With this function, in a work detail page, when add attachment, it
allows the user to more easily file the new document into the case
folder, without requiring the user to navigate to the case folder.
Configuration steps:
1. Replace the 'Add Document From Local File System' action inside the attachment widget with a Script Action EventAction.
2. Configure the EventAction
2.1 Set the action label as "Add Document From Local File System"
2.2 Set the event name as "icm.AddDocToBothCaseAndAttachment"
2.3 Set the Enable this event action as
var attachment = this.getActionContext("Attachment");
if (attachment && attachment.length > 0) {
attachment = attachment[0];
}
if ((attachment && (attachment.get("readOnly") == true)) || (!attachment)){
return false;
}else{
return true;
}
3. Put the script below into a script adapter inside work detail page. Disable the outbound event of the script adaptor.
4. Wiring the page container "icm.SendWorkItem" event to script adaptor's incoming event.
5. Wiring the attachment widget "icm.AddDocToBothCaseAndAttachment" event to script adaptor's inbound event.
6. Wiring the script adaptor outbound event to attachment page widget "icm.AddAttachment" event.
7. Optional, put a case document in the page to observe the case document updates.
Usage:
1. Open work item in work detail page, select a attachment in attachment widget.
2. Click on the "Add Document From Local File System" action button.
3. In the add document dialog, select a local document to add.
Script:
var self = this;
/*Wire to page container icm.SendWorkItem event, retrieve the workitem related case.*/
if (payload.eventName == "icm.SendWorkItem") {
self.workItemEdt = payload.workItemEditable;
self.workItemEdt.retrieveStep(function() {
self.caze = self.workItemEdt.getCase();
});
}
/*Wire to event action on attachment, which published the user configured event icm.AddDocToBothCaseAndAttachment*/
if (payload.eventName == "icm.AddDocToBothCaseAndAttachment") {
/*Get the selected attachment sent from event action*/
self.attachment = payload.Attachment;
/*Callback to add case document as attachment*/
var _addToAttachment = function(contentItem) {
self.onPublishEvent("icm.SendEventPayload", {
"attachmentName": self.attachment.id,
"documents": [contentItem]
});
};
/*retrieve the case folder, make it as the parent folder of the add document dialog*/
self.caze.retrieveCaseFolder(function() {
var parentFolder = self.caze.getCaseFolder();
require(["ecm/widget/dialog/AddContentItemDialog"], function(AddContentItemDialog) {
/*Create the add document dialog*/
self.addContentItemDialog = new AddContentItemDialog();
var contentItemGeneralPane = self.addContentItemDialog.addContentItemGeneralPane;
/*Show the add document dialog*/
self.addContentItemDialog.show(parentFolder.repository,
parentFolder, true, false, _addToAttachment, null, false, null, true);
/*Enable folder select in save in*/
contentItemGeneralPane.folderSelector.setDisabled(false);
});
});
}
Không có nhận xét nào:
Đăng nhận xét