Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello,
I am trying to create a change issue with the following code and then create a link to an Object. The creation of the change issue itself works and it gets stored in the database. But when I add the code for the link I get an error
wt.util.WTRuntimeException: ERROR: Can't initialize an ObjectReference to null
The code is:
ReferenceFactory rf = new ReferenceFactory();
WTChangeIssue issue1 = WTChangeIssue.newWTChangeIssue(name);
WTReference ref = rf.getReference(obid);
ChangeIssue ci = (ChangeIssue)ChangeHelper2.service.saveChangeIssue(issue1);
ReportedAgainst ra = ReportedAgainst.newReportedAgainst((Changeable2) ref.getObject(), ci);
wt.fc.collections.WTArrayList al = new wt.fc.collections.WTArrayList();
al.add(ra);
ChangeHelper2.service.storeAssociations(issue1, al);
If you need to know aditional things, let me know. The last line of code is the one, that is giving me the error (at least the error is not there without this line).
I commented out the last line of the code and put a check there.
obid is not null
ref is not null
ci is not null
Only with the last line I get the error message.
When I change the last line toChangeHelper2.service.storeAssociations(ci, al); I get the same error message.
I am on 10.0 and there is
WTCollection storeAssociations(ChangeItemIfc changeItem, WTCollection links) throws ChangeException2, WTException
Stores the association objects for the given change item.
I will try the other method:
Vector storeAssociations(Class theClass, ChangeItemIfc ci, Vector changeables) throws ChangeException2, WTExceptionCreates and stores the correct association object type between the ChangeItemIfc object and the Changeable2 objects in the input vector and returns a vector of the persisted association objects.
Edit: I get the same error message there..
but the first one should also work, shouldn't it?
In Reply to Chris Rosato:
It looks like what you're trying to "store" isn't actually in WC yet.
issue1 is just the object you initialized, but ci is actually the object in the DB.
Also, I'm not sure what v you're on but for v8 and v9.1, the syntax is:
storeAssociations<file: c:\documents%20and%20settings\cmrosato\my%20documents\projects\windchill-epdm\random%20documents\v91_m050%20javadoc\wt\change2\changeservice2.html#storeassociations%28java.lang.class,%20wt.change2.changeitemifc,%20java.util.vector%29=">(Class< theClass, ChangeItemIfc<file: c:\documents%20and%20settings\cmrosato\my%20documents\projects\windchill-epdm\random%20documents\v91_m050%20javadoc\wt\change2\changeitemifc.html="> ci, Vector< changeables)
Stores all the associations between the ChangeItemIfc object and the Changeable2 objects in the input vector and returns a vector of the persisted association objects.
It looks like you're missing the Class from the method.
Thanks
Chris
Thanks for your help, it works now.
martin
In Reply to Chris Rosato:
Ah ok, but unless something changed drastically in v10, it still looks like you are not saving the ReportedAgainst link, so it's not in the DB.
Try adding
PersistenceServerHelper.manager.insert(ra);
Between when you initialize it and add it to the list.
Thanks
Chris
Martin, would you be willing to share the final code. I am looking at doing something similar and would appreciate the "jump" start with the code.
attached you will find my jsp file that creates the change issue.