Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hi!
I want to set state for the WTDocument by java code through rms like this:
RemoteMethodServer rms = RemoteMethodServer.getDefault();
rms.setUserName("***");
rms.setPassword("***");
WTChangeOrder2 cho = (WTChangeOrder2)( new ReferenceFactory()).getReference("VR:wt.change2.WTChangeOrder2:16423065").getObject();
wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore(cho);
wt.doc.WTDocument wtd = null;
wt.fc.QueryResult qr2 = new wt.fc.QueryResult();
while (qr.hasMoreElements())
{
wtd = (wt.doc.WTDocument)qr.nextElement();
Class argTypes[] = {wt.lifecycle.LifeCycleManaged.class, wt.lifecycle.State.class};
Object argValues[] = {(wt.lifecycle.LifeCycleManaged)wtd, wt.lifecycle.State.toState("CANCELLED")};
rms.invoke("setState", wt.lifecycle.LifeCycleServerHelper.service.getClass().getName(), null, argTypes, argValues);
}
But I have an exception like this:
WARNING: The ManagerService is not initialized! This can be caused by:
1) Attempting to invoke a server only method from a remote client
2) Attempting to invoke a method on a service from the constructor or static initializer of another service
What is wrong?
You need to do this way.
RemoteMethodServer rms = RemoteMethodServer.getDefault();
rms.setUserName("***");
rms.setPassword("***");
rms.invoke("yourMethodName", Yourclass.class.getName,null,argTypes,argValues);
// Put your logic inside your method
public yourMethodName() {
WTChangeOrder2 cho = (WTChangeOrder2)( new ReferenceFactory()).getReference("VR:wt.change2.WTChangeOrder2:16423065").getObject();
wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore(cho);
wt.doc.WTDocument wtd = null;
wt.fc.QueryResult qr2 = new wt.fc.QueryResult();
while (qr.hasMoreElements())
{
wtd = (wt.doc.WTDocument)qr.nextElement();
State st=State.toState(String state);
LifeCycleHelper.service.setLifeCycleState(wtd,st);
}
}
Let me know if you need further detail
Vino, I have changed the method to the LifeCycleHelper.service.setLifeCycleState(wtd,st) and now it's working fine. Please correct me. If I want to use your sample, so I should have my custom class with the method on the server side?
Yes that's right. You should have custom class and from that you need to invoke that method of any other class or on same class server side. As yogesh said your custom class should implement RemoteAccess.
Just a quick note:
*ServerHelper and *SrvHelper classes are for use with the method server itself, not by other processes.
As such they are not remotely callable.
LifeCycleHelper, on the other hand, is intended for use on both the client and server -- and thus is remotely callable.
The class you call with rms.invoke() needs to extend StandardManager and implement RemoteAccess, Serializable. I guess LifeCycleServerHelper does not satisfy that criteria and cannot be called like that. As Vino said, write your own class containing yourMethodName() inside a class that extends StandardManager and implements RemoteAccess, Serializable.