Technical Blog Post
Abstract
Attachment validation that is based on which step response is selected
Body
Hi there, here is a small trick to validate that whatever attachment you have on your step has documents attached to it and that the attachment content is empty.
- Add a Script Adaptor widget to the hidden widgets area on a work details page
- Wire an inbound event from the Page Container's Send Work Item to the Script Adaptor's Receive Event.
- The additional data validation logic will be triggered when the appropriate response button is clicked.
function validateWItemAttachments(propertiesCollection) {
var emptyattachment = false;
console.log("emptyattachment Flag is--" + emptyattachment);
if (propertiesCollection) {
var k;
for (k in propertiesCollection) {
if (propertiesCollection.hasOwnProperty(k)) {
var p = propertiesCollection[k];
if (p.dataType == "xs:attachment") {
console.log("Found Attachment Field--" + k);
console.log(p);
console.log(p.value);
p.retrieveAttachmentContents(function(items) {
console.log(items);
if (items.length == 0) {
emptyattachment = true;
}
});
}
}
}
}
return emptyattachment;
}
var workItemEdt = payload.workItemEditable;
var coord = payload.coordination;
var propertiesCollection = payload.workItemEditable.propertiesCollection;
require(["icm/model/properties/controller/ControllerManager", "icm/base/Constants", "dojo/date"],
function(ControllerManager, Constants, date) {
// use the validate coordination topic to handle validation of the
// the attachments
coord.participate(Constants.CoordTopic.VALIDATE, function(context, complete, abort) {
/* Begin Check for attachments for reposne */
if (context[Constants.CoordContext.WKITEMRESPONSE] === "Send Final SOA For Tenant") {
var inValidAttachmentsFlag = validateWItemAttachments(propertiesCollection);
if (inValidAttachmentsFlag) {
var messageDialog = new ecm.widget.dialog.MessageDialog({
text: "Invalid Attachment !"
});
messageDialog.show();
abort({
'silent': true
});
} else {
complete();
}
}
//else then complete the work item as usual
else{
complete();
}
});
});
the general idea of the code is to get the properties collection of the work item than iterating over the collection to get every property with the data type of xs:attachment then we retrieve the content items attached to this property and check the content item list , if the length of the list is there that means that no content items are attached then we raise a flag and make it true ,
we return the flag from the attachment validation function and check it after calling the function , if the flag is true we input an information message that one ot the attachment needs items to be add to it
you can extend the code by iterating over the properties collection and checking each attachment property by name and checking the content list of the items for this property and issue different error messages according to the different properties
you can extend also the validation for any number of responses using this validateWItemAttachments() function
for further inquires please don't hesitate to contact me
Thanks
UID
ibm11280830