cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Complete Task Transitions to validate attachment

Durga
5-Regular Member

Complete Task Transitions to validate attachment

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
imendiola
11-Garnet
(To:Durga)

Hi Durga,

 

there are 2 options for this:

  • You can create an external Java class with a method that can be invoked from the transition tab. This allows you to modify the logic and apply changes to all running workflows after a server restart
  • You can write the code directly in the transition tab, but if you need to modify the logic it will not apply to running workflows and you need to specify full package path for each class

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

http://www.prambanan-it.comIker Mendiola - Prambanan IT Services

View solution in original post

4 REPLIES 4
imendiola
11-Garnet
(To:Durga)

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

http://www.prambanan-it.comIker Mendiola - Prambanan IT Services
Durga
5-Regular Member
(To:imendiola)

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. 

imendiola
11-Garnet
(To:Durga)

Hi Durga,

 

there are 2 options for this:

  • You can create an external Java class with a method that can be invoked from the transition tab. This allows you to modify the logic and apply changes to all running workflows after a server restart
  • You can write the code directly in the transition tab, but if you need to modify the logic it will not apply to running workflows and you need to specify full package path for each class

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

http://www.prambanan-it.comIker Mendiola - Prambanan IT Services

View solution in original post

Durga
5-Regular Member
(To:imendiola)

Hi Mendiola,

 

Thanks a lot, it worked out.

 

Regards,

durga

Announcements