Hi
I´m trying to retrieve an value from a class and returning a string value in to another class.
The return value is not a string it´s returning the class name and an object id.
Class IBAHandler
public class IBAHandler {
public String s;
public String obj;
public String IBAHandler() throws WTException {
//this.changeOrder = co;
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
wt.fc.WTReference ref = rf.getReference("VR:wt.change2.WTChangeOrder2:9049460");
wt.fc.Persistable obj = ref.getObject();
String s = obj;
return s;
}
Class RetriveHandler
if (workshops != null) {
IBAHandler workshops = new IBAHandler();
this.workshops=s;
} else {
workshops="Workshops not set";
}
(return workshops: ext.itt.www.productService.IBAHandler@231ef93)
Regards
Hi Ann,
workshops is the name of the variable of IBAHandler type not String type.
So, if you print workshop you will get the fully qualified package name along with the hashcode.
Its a fundamental java property.
If you want to get the value of the String s of IBAHandler.
Then print workshop.s insted of only workshop.Better if you use getter method to access the variable.
Thanks,
Kaushik
Hi
Thanks, I´m new, so I´m probably missing the basics. Right now it´s try and error.
I have tried with your suggestion and get/set method, but received only an null value.
I´ll try again, never give up never surrender
Thanks again
Hello,
What is your objective actually ?
You want to pass the Change Order name ?
I am not sure how your code is running cause it should give you class cast exception in following lines.
wt.fc.Persistable obj = ref.getObject();
String s = obj;
Thanks,
Kaushik
Hi
thanks,
So i'm still trying to pass the value but can't retriver the obi for the WTChangeOrder2
THe return value is null.
But if I put in an obi instead of the eco, I can retrieve the value.
What is it that I'm missing?
Retriveclass
public class IBAHandler2() {
public IBAHandler2() {}
public void setIBAHandler2(WTChangeOrder2 co) throws WTException {
this.eco = co;
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
wt.fc.WTReference ref = rf.getReference(eco);
wt.fc.Persistable obj = ref.getObject();
com.ptc.core.lwc.server.LWCNormalizedObject value = new com.ptc.core.lwc.server.LWCNormalizedObject(obj, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
String work = (java.lang.String) value.get("Workshops");
this.s = work;
}
public String getIBAHandler2(String s){
return this.s;
}
}
return class
IBAHandler2 workshops = new IBAHandler2();
Test= workshops.s;
Hi,
Instead of passing obj in LWCNormalizedObject pass co directly.
com.ptc.core.lwc.server.LWCNormalizedObject value = new com.ptc.core.lwc.server.LWCNormalizedObject(co, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
Additionally print co to make sure that it's not null.Check the IBA name "Workshops" too as it's case sensitive.
Regards,
Kaushik
Hi
Thanks for the replay.
Probably I´m missing something basic again.
"Workshops" is working.
But I can´t retrive the obi for the WTChangeOrder2 it´s only null, if I´m not using a hardcoded obi.
Regards
Anna
Hi Ann,
Sorry for the late reply.
By reading your code I am assuming two thing.
1> You are using WC 10.1 or 10.0
2> You want to retrieve the value of an IBA named "Workshop" from the WTChangeOrder2 object using the LWCNormalizedObject API.
If my above assumptions are correct then there raise another question.
LWCNormalizeObject take Persistable as an input.So how we will find Persistable from WTChangeOrder2.
Now Persistable is an interface wihich is implemented by many classes in Windchill like WTPart,WTDocument,WTChangeOrder2 etc.
If a class is implementing Persistable then we can use that class's object as Persistable.
In your code below
public void setIBAHandler2(WTChangeOrder2 co) throws WTException {
this.eco = co;
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
wt.fc.WTReference ref = rf.getReference(eco);
wt.fc.Persistable obj = ref.getObject();
com.ptc.core.lwc.server.LWCNormalizedObject value = new com.ptc.core.lwc.server.LWCNormalizedObject(obj, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
At the time of creating LWCNormalizedObject you can use both
a> com.ptc.core.lwc.server.LWCNormalizedObject value = new com.ptc.core.lwc.server.LWCNormalizedObject(obj, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
and
b> com.ptc.core.lwc.server.LWCNormalizedObject value = new com.ptc.core.lwc.server.LWCNormalizedObject(co, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
They are same.
If you want OBID from any object you try below code.
ReferenceFactory factory = new ReferenceFactory();
ObjectReference objRef = (ObjectReference)factory.getReference(persistable_object);
Persistable per=(( Persistable) objRef.getObject());
Thanks,
Kaushik