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

We are happy to announce the new Windchill Customization board! Learn more.

extract initial characters from attribute

RoyCrerar
14-Alexandrite

extract initial characters from attribute

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

1 REPLY 1

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

Top Tags