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

Call custom class

SOLVED
Newbie

Call custom class

Hi all,

I wrote a workflow expression but it was quite long.

So I used javac to create package and store it in proper dir inside codebase/ext.

But when I'm calling my class via expression in workflow manager I get error class not found.

Checking Syntax...

e:\Windchill_9.0\Windchill\temp\WfExpression269020934.java:40: package com does not exist

ext.workflow.myClass(primaryBusinessObject);

^

1 error

Syntax check complete.

Can you help me, please?

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Call custom class

What are you expecting to get by this code?

To get class instance you shoud write "new ext.test.TestingClass();",

To call method "ext.test.TestingClass.main();".

View solution in original post

4 REPLIES 4

Re: Call custom class

Here's an example of a call to a custom class that we use.

Code In workflow Template Activity, on Start Transition

//Add pBONumber to Assignment names

ext.alcon.workflow.WorkflowHelper.replaceInAssignmentName(self, "\\{pBONumber}", pBONumber);

custom class location

D:\PTC\Windchill_10.1\Windchill\codebase\ext\alcon\workflow\WorkflowHelper.class

Called Method in custom class

/**

* Replace a given string with another given string in the names of the assignments associated with the given pBO.

*/

public static void replaceInAssignmentName(WTObject primaryBusinessObject, String replaceThis, String withThat) {

try {

Enumeration processes = WfEngineHelper.service.getAssociatedProcesses(primaryBusinessObject,null,((WTContained)primaryBusinessObject).getContainerReference());

while(processes.hasMoreElements()) {

WfProcess process = (WfProcess) processes.nextElement();

QueryResult nodes = process.getContainerNodes();

while(nodes.hasMoreElements()){

WTObject wtObj = (WTObject) nodes.nextElement();

LocalizableMessage wtObjDispTypeLM = wtObj.getDisplayType();

String wtObjDispType = wtObjDispTypeLM.getLocalizedMessage(wt.session.SessionHelper.manager.getLocale());

String wtObjName = null;

if(wtObjDispType.contains("Wf Assigned Activity")){

wtObjName = ((WfActivity)wtObj).getName();

String wtObjNewName = wtObjName.replaceFirst(replaceThis, withThat);

((WfActivity)wtObj).setName(wtObjNewName);

PersistenceHelper.manager.save((Persistable) wtObj);

}

}

PersistenceHelper.manager.save((Persistable) process);

}

}

catch(WTException e) {

e.printStackTrace();

LOGGER.error("Error while adding PBONumber to Assignment Name: " + e);

}

}

Re: Call custom class

Thanks for your reply.

Did you use standard Javac or Rational Rose?

I wrote simple TestingClass.java

package ext.test;


import java.io.File;
import java.io.FileWriter;

public class TestingClass {
public static void main (String[] args) {
try {
FileWriter outputStream = new FileWriter("C:\\test\\helloworld.txt");
for (int i = 0; i < 25; i++) {
outputStream.write("Hello World!" + "\r\n");
}
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Placed it inside of <wc.home>\codebase\ext\test

compiled using javac ext\test\TestingClass.java

<wc.home>\codebase\ext\test\TestingClass.class was created

Then I used my class in Workflow Expression

try {

ext.test.TestingClass();

} catch (Exception e) {

e.printStackTrace();

}

syntax check returned

Checking Syntax...

e:\Windchill_9.0\Windchill\temp\WfExpression269079314.java:39: package ext does not exist

ext.test.TestingClass();

^

1 error

Syntax check complete.

I catched similar exception at runtime

Re: Call custom class

What are you expecting to get by this code?

To get class instance you shoud write "new ext.test.TestingClass();",

To call method "ext.test.TestingClass.main();".

View solution in original post

Re: Call custom class

Thanks a lot, it's functional now.

Beginners mistake.

It was only testing class, and not functional I think.

Now I can move all my expressions into own class(es), yippee.

Announcements
LiveWorx Call For Papers Happening Now!