<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Complete Task Transitions to validate attachment in Windchill Customization</title>
    <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748972#M3632</link>
    <description>&lt;P&gt;Hi Mendiola,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot, it worked out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;durga&lt;/P&gt;</description>
    <pubDate>Sat, 18 Sep 2021 04:43:41 GMT</pubDate>
    <dc:creator>Durga</dc:creator>
    <dc:date>2021-09-18T04:43:41Z</dc:date>
    <item>
      <title>Complete Task Transitions to validate attachment</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748589#M3628</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm trying to figure out how to write an expression which will validate attachment before completing the task in customized workflow.&lt;/P&gt;
&lt;P&gt;The scenario is the user shouldn't be able to complete his task without attaching required documents.&lt;/P&gt;
&lt;P&gt;Tried referring&amp;nbsp;Article - CS158546, however failing to understand which class to use to validate attachment.&lt;/P&gt;
&lt;P&gt;The expression needs to written in transition tab in workflow.&lt;/P&gt;
&lt;P&gt;Any references will be appreciated.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Durga&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:15:32 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748589#M3628</guid>
      <dc:creator>Durga</dc:creator>
      <dc:date>2024-03-15T14:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Complete Task Transitions to validate attachment</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748631#M3629</link>
      <description>&lt;P&gt;Hi Durga,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;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 &amp;lt; 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");
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The text included in the exception thrown will be shown to the user in the UI.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 13:54:15 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748631#M3629</guid>
      <dc:creator>imendiola</dc:creator>
      <dc:date>2021-09-16T13:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Complete Task Transitions to validate attachment</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748752#M3630</link>
      <description>&lt;P&gt;Hi Garnet,&lt;/P&gt;
&lt;P&gt;Thank you for the reply.&lt;/P&gt;
&lt;P&gt;To put some more light on exactly I'm looking for is.&lt;/P&gt;
&lt;P&gt;I've a customized workflow. User gets task accordingly.&lt;/P&gt;
&lt;P&gt;Its should be mandate that user has to attach documents, else he should not be able to complete his task.&lt;/P&gt;
&lt;P&gt;Referring some articles found out need to mention a condition in workflow task in transition tab to achieve it.&lt;/P&gt;
&lt;P&gt;Attach is the image with incomplete sample code which just prints " Please attach required documents"&lt;/P&gt;
&lt;P&gt;I'm struggling to find out what class name or which object name to be mentioned so that it will check for attachment container.&lt;/P&gt;
&lt;P&gt;Case referring&amp;nbsp;Article - CS158546 and help center.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Durga.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 05:55:09 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748752#M3630</guid>
      <dc:creator>Durga</dc:creator>
      <dc:date>2021-09-17T05:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Complete Task Transitions to validate attachment</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748761#M3631</link>
      <description>&lt;P&gt;Hi Durga,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there are 2 options for this:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;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&lt;/LI&gt;
&lt;LI&gt;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&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;For the first option you can create a Java class with the following code:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;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 &amp;lt; attachmentsVector.size(); i++) {
            Object obj = attachmentsVector.get(i);
            if (obj instanceof ApplicationData) {
                isAnyAttachment = true;
                break;
            }
        }
        if (!isAnyAttachment) {
            throw new WTException("Please attach required documents");
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;and invoke it from the transition tab just with:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;your.java.package.TestCheckAttachment.checkAttachment(primaryBusinessObject);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you prefer the second option, you can write something like this directly in the transition tab:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;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 &amp;lt; 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");
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 07:05:34 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748761#M3631</guid>
      <dc:creator>imendiola</dc:creator>
      <dc:date>2021-09-17T07:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Complete Task Transitions to validate attachment</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748972#M3632</link>
      <description>&lt;P&gt;Hi Mendiola,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot, it worked out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;durga&lt;/P&gt;</description>
      <pubDate>Sat, 18 Sep 2021 04:43:41 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/Complete-Task-Transitions-to-validate-attachment/m-p/748972#M3632</guid>
      <dc:creator>Durga</dc:creator>
      <dc:date>2021-09-18T04:43:41Z</dc:date>
    </item>
  </channel>
</rss>

