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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Complete Task Transitions to validate attachment

Durga
13-Aquamarine

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

 

ACCEPTED SOLUTION

Accepted Solutions
imendiola
13-Aquamarine
(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
13-Aquamarine
(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
13-Aquamarine
(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
13-Aquamarine
(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
Durga
13-Aquamarine
(To:imendiola)

Hi Mendiola,

 

Thanks a lot, it worked out.

 

Regards,

durga

Announcements

Top Tags