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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Listener to watch for file & start workflow

ljett-4
1-Visitor

Listener to watch for file & start workflow

Hello ALL,

I hate to be lazy, but my search to date, hasn't produced much.

I am not much on windchill listeners, but my current need is for a listener that checks a server/shared folder, for a file with a specific name.

Maybe every 5 minutes or such. Then as soon as it finds that file, it starts/initiates/initializes/? a workflow.

I hope the listener area isn't as limited as the business rules are...4 ootb or lots of coding....lol

Thanks

Larry Jett
datajett@aol.com

3 REPLIES 3

‌Larry,

As I understand Windchill listeners they can listen for and get triggered on events on Windchill objects like WTDoc checkin etc. What you want is probably to set up a service that listen for file system events as you will find examples of if you google for 'java file listener' then use that to kick off your workflow.

sbairi-2
2-Explorer
(To:ljett-4)

There are multiple ways you can accomplish this. It depends upon what kind of system you are watching the folders on and you can create a trigger to initiate the workflow. Here are the options that I can think of:

  1. Option 1 - Don't tax the Windchill System: In this option, you would write some code that is a scheduled task that you run on you operating system every 5 mins or so. Then if a specific file is created, then that task will call a Java Class that will remotely connect to the Windchill Server and initiate a remote Java class on Windchill. This Windchill class will need to be coded to initiate the Workflow.
  2. Option 2 - Through Windchill System (may impact Windchill System performance): In this option, you'll have to create a workflow. In that workflow there should be a timer set for 5 mins or so and after the 5 mins, the flow will go to an OR condition. This OR condition will have java code that will check for the file in a specific folder in a specific machine where you are watching the file for. If its created, then the OR condition will route to success path if not then it will go back to the timer.
    • For Success path, you'll need to create a sub-process and that sub-process will be the workflow that you want to initiate whenever you have the file created in the specified folder of interest.

Here is the workflow expression code, I have been working on. With timer.

java.io.File folder = new File("D:\\SHAREFILE_SYNC\\DOCS\\");
java.io.File[] listOfFiles = folder.listFiles();

for (java.io.File file : listOfFiles) {
   if (file.isFile()) {
     String fileName = "";
     fileName = file.getName();
     if (filename.endsWith(".pdf") {
       System.out.println("WorkFlow Start");
       wt.workflow.engine.WfEngineHelper.service.startProcess(proc, data, 0);
       break;
     }
   }
}

I have been pulled off this task, but I will see how this goes, when I get back to it.

But I might need to adjust this to look in subfolders also. Because the pdf's will be in sub folders of the above top folder.

I have not thought this code out, but its a good start, till I check workflow syntax check

for (java.io.File file : listOfFiles) {

if (file.isFile()) {

  String fileName = "";

  fileName = file.getName();

  if (filename.endsWith(".pdf") {

   System.out.println("WorkFlow Start");

   wt.workflow.engine.WfEngineHelper.service.startProcess(proc, data, 0);

   break;

  }

}

else if(file.isDirectory()){

  java.io.File[] listOfFilesSub = file.listFiles();

  for (java.io.File fileSub : listOfFilesSub) {

   if (fileSub.isFile()) {

    String fileNameSub = "";

    fileNameSub = file.getName();

    if (filename.endsWith(".pdf") {

     System.out.println("WorkFlow Start");

     wt.workflow.engine.WfEngineHelper.service.startProcess(proc, data, 0);

     break;

    }

   }

  }

}

}

Larry Jett

Announcements

Top Tags