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.
the additional validation will be placed in a Script Adapter widget.
- 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;
}
});
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;
}
}
}
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) {
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();
// 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();
}
'silent': true
});
} else {
complete();
}
}
//else then complete the work item as usual
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
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
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
Hi,
ReplyDeleteI want to validate attachment in case of no attachment is attached in case when particular response button pressed. But i'm unable to do so. Let's say, when user click on response button like "Forward Case" than a pop up will appear in case of no attachments attached otherwise case proceed smoothly as it is.
Any suggestions please. I tried your above code, but no luck.
one problem with this code sample is that retrieving the attachments will make an asynchronous code , and you should proceed with the checking of attachments after the call is done and you can check the results but what happens actually is that sometimes the code will not wait for retrieving the attachments and return a flag without completing the check
ReplyDeletei made a newer version of this code sample using deferred to resolve the problem of asynchronous call during the check , i will get the code and send it to you , if you can provide me with an email that would be great and i will make a new post with it here
Hi Ziyhed,
ReplyDeleteThanks for your reply. Here is my email junaid.azam786@gmail.com. :)
Hi Ziyad,
ReplyDeletei am having the similar requirement,Please post the updated code to my email id pandalneni@gmail.com
Hi Ziyad,
ReplyDeletei am having the similar requirement,It would be great if you can share the updated code to my email id kezkoy@gmail.com
Hi, if you want to validate and show a pop-up to user in case of document is not attached then please try this, https://iparagons.com/blog/2020/09/09/attachment-validation-in-ibm-case-manager-5-2/
ReplyDeleteRespect and I have a neat present: How Much Home Renovation Can I Afford home repairs contractors near me
ReplyDelete