Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hi, I am looking to extract the first 4 characters from an attribute to use elsewhere in Windchill. Is this possible?
I am attempting to grab the project code from a much longer project name and the first 4 characters are that code.
Solved! Go to Solution.
Hi Roy,
Not directly, but with yes. In Windchill 10.2 you can do it by using com.ptc.core.lwc.server.PersistableAdapter API.
First get the IBA value and then use core java substring API to get first desired characters.
Something like below:
Note: Here I took WTDocument handle, but you can take any object type.
// Retrieve handle for WTPart ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.doc.WTDocument:228878"); WTDocument doc = (WTDocument)PersistenceHelper.manager.refresh(oid); System.out.println(" ### Handler Retrieved..!!!"); Locale locale = SessionHelper.getLocale(); PersistableAdapter perAdap = new PersistableAdapter(doc, null,locale,new SearchOperationIdentifier()); perAdap.load("COUNTRY"); Object val = perAdap.get("COUNTRY"); if (val != null) { System.out.println(" Value is -> " + val.toString().substring(0, 3)); }
Above applies to IBA value. But in your case you're looking for name field. So you can directly query name using getName(); API.
For example:
ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.doc.WTDocument:228878"); WTDocument doc = (WTDocument)PersistenceHelper.manager.refresh(oid); System.out.println(" Value is -> " + doc.getName().substring(0, 3));
I hope it will help you.
Regards,
Shirish
Hi Roy,
Not directly, but with yes. In Windchill 10.2 you can do it by using com.ptc.core.lwc.server.PersistableAdapter API.
First get the IBA value and then use core java substring API to get first desired characters.
Something like below:
Note: Here I took WTDocument handle, but you can take any object type.
// Retrieve handle for WTPart ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.doc.WTDocument:228878"); WTDocument doc = (WTDocument)PersistenceHelper.manager.refresh(oid); System.out.println(" ### Handler Retrieved..!!!"); Locale locale = SessionHelper.getLocale(); PersistableAdapter perAdap = new PersistableAdapter(doc, null,locale,new SearchOperationIdentifier()); perAdap.load("COUNTRY"); Object val = perAdap.get("COUNTRY"); if (val != null) { System.out.println(" Value is -> " + val.toString().substring(0, 3)); }
Above applies to IBA value. But in your case you're looking for name field. So you can directly query name using getName(); API.
For example:
ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.doc.WTDocument:228878"); WTDocument doc = (WTDocument)PersistenceHelper.manager.refresh(oid); System.out.println(" Value is -> " + doc.getName().substring(0, 3));
I hope it will help you.
Regards,
Shirish