Hi all,
I'm trying to figure out how to write an expression which will validate attachment before completing the task in customized workflow.
The scenario is the user shouldn't be able to complete his task without attaching required documents.
Tried referring Article - CS158546, however failing to understand which class to use to validate attachment.
The expression needs to written in transition tab in workflow.
Any references will be appreciated.
Regards,
Durga
Solved! Go to Solution.
Hi Durga,
there are 2 options for this:
For the first option you can create a Java class with the following code:
package your.java.package;
import java.beans.PropertyVetoException;
import java.util.Vector;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.fc.PersistenceHelper;
import wt.fc.WTObject;
import wt.util.WTException;
public class TestCheckAttachment {
public static void checkAttachment(WTObject primaryBusinessObject) throws WTException, PropertyVetoException {
primaryBusinessObject = (WTObject) PersistenceHelper.manager.refresh(primaryBusinessObject);
ContentHolder contentHolder = ContentHelper.service.getContents((ContentHolder) primaryBusinessObject);
Vector attachmentsVector = ContentHelper.getApplicationData(contentHolder);
boolean isAnyAttachment = false;
for (int i = 0; i < attachmentsVector.size(); i++) {
Object obj = attachmentsVector.get(i);
if (obj instanceof ApplicationData) {
isAnyAttachment = true;
break;
}
}
if (!isAnyAttachment) {
throw new WTException("Please attach required documents");
}
}
}
and invoke it from the transition tab just with:
your.java.package.TestCheckAttachment.checkAttachment(primaryBusinessObject);
If you prefer the second option, you can write something like this directly in the transition tab:
wt.content.ContentHolder contentHolder = wt.content.ContentHelper.service.getContents((wt.content.ContentHolder) primaryBusinessObject);
java.util.Vector attachmentsVector = wt.content.ContentHelper.getApplicationData(contentHolder);
boolean isAnyAttachment = false;
for (int i = 0; i < attachmentsVector.size(); i++) {
Object obj = attachmentsVector.get(i);
if (obj instanceof wt.content.ApplicationData) {
isAnyAttachment = true;
break;
}
}
if (!isAnyAttachment) {
throw new wt.util.WTException("Please attach required documents");
}
Regards
Iker Mendiola - Prambanan IT Services |
Hi Durga,
I do not know what you need to check exactly, but here is an example to check if there is any attachment with a given file name:
import java.beans.PropertyVetoException;
import java.util.Vector;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.fc.PersistenceHelper;
import wt.fc.WTObject;
import wt.util.WTException;
public class TestCheckAttachment {
public static void checkAttachment(WTObject primaryBusinessObject, String attachmentNameToCheck) throws WTException, PropertyVetoException {
primaryBusinessObject = (WTObject) PersistenceHelper.manager.refresh(primaryBusinessObject);
ContentHolder contentHolder = ContentHelper.service.getContents((ContentHolder) primaryBusinessObject);
Vector attachmentsVector = ContentHelper.getApplicationData(contentHolder);
boolean isOk = false;
for (int i = 0; i < attachmentsVector.size(); i++) {
Object obj = attachmentsVector.get(i);
if (obj instanceof ApplicationData) {
ApplicationData attachment = (ApplicationData) obj;
String attachmentName = attachment.getFileName();
if (attachmentName.equals(attachmentNameToCheck)) {
isOk = true;
break;
}
}
}
if (!isOk) {
throw new WTException("There is no attachment with name " + attachmentNameToCheck + ". Task cannot be completed");
}
}
}
The text included in the exception thrown will be shown to the user in the UI.
Regards
Iker Mendiola - Prambanan IT Services |
Hi Garnet,
Thank you for the reply.
To put some more light on exactly I'm looking for is.
I've a customized workflow. User gets task accordingly.
Its should be mandate that user has to attach documents, else he should not be able to complete his task.
Referring some articles found out need to mention a condition in workflow task in transition tab to achieve it.
Attach is the image with incomplete sample code which just prints " Please attach required documents"
I'm struggling to find out what class name or which object name to be mentioned so that it will check for attachment container.
Case referring Article - CS158546 and help center.
Regards,
Durga.
Hi Durga,
there are 2 options for this:
For the first option you can create a Java class with the following code:
package your.java.package;
import java.beans.PropertyVetoException;
import java.util.Vector;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.fc.PersistenceHelper;
import wt.fc.WTObject;
import wt.util.WTException;
public class TestCheckAttachment {
public static void checkAttachment(WTObject primaryBusinessObject) throws WTException, PropertyVetoException {
primaryBusinessObject = (WTObject) PersistenceHelper.manager.refresh(primaryBusinessObject);
ContentHolder contentHolder = ContentHelper.service.getContents((ContentHolder) primaryBusinessObject);
Vector attachmentsVector = ContentHelper.getApplicationData(contentHolder);
boolean isAnyAttachment = false;
for (int i = 0; i < attachmentsVector.size(); i++) {
Object obj = attachmentsVector.get(i);
if (obj instanceof ApplicationData) {
isAnyAttachment = true;
break;
}
}
if (!isAnyAttachment) {
throw new WTException("Please attach required documents");
}
}
}
and invoke it from the transition tab just with:
your.java.package.TestCheckAttachment.checkAttachment(primaryBusinessObject);
If you prefer the second option, you can write something like this directly in the transition tab:
wt.content.ContentHolder contentHolder = wt.content.ContentHelper.service.getContents((wt.content.ContentHolder) primaryBusinessObject);
java.util.Vector attachmentsVector = wt.content.ContentHelper.getApplicationData(contentHolder);
boolean isAnyAttachment = false;
for (int i = 0; i < attachmentsVector.size(); i++) {
Object obj = attachmentsVector.get(i);
if (obj instanceof wt.content.ApplicationData) {
isAnyAttachment = true;
break;
}
}
if (!isAnyAttachment) {
throw new wt.util.WTException("Please attach required documents");
}
Regards
Iker Mendiola - Prambanan IT Services |
Hi Mendiola,
Thanks a lot, it worked out.
Regards,
durga