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

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

I want to retrieve the part attribute

RaikarRaghu
10-Marble

I want to retrieve the part attribute

I have the change Notice Number. From the changenotice number get the changables after from the changables i want only part. From that part i want to retrieve the attribute "Material_Type".

ACCEPTED SOLUTION

Accepted Solutions

Give it a try this way

				try {
					
					QuerySpec qs = new QuerySpec(WTChangeOrder2.class);
					
					SearchCondition searchcondition = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.NUMBER, SearchCondition.EQUAL, "CN0007698");
					

					qs.appendWhere(searchcondition, new int[]{0});
					final QueryResult qr = PersistenceHelper.manager.find(qs);
					while (qr.hasMoreElements()) {
						WTChangeOrder2 ecn = (WTChangeOrder2) qr.nextElement();
						System.out.println(" Found Change Order Number: " + ecn.getNumber());
						
						ReferenceFactory rf = new ReferenceFactory();
						WTReference reference = (WTReference) rf.getReference(ecn);
						WTChangeOrder2 changeNotice = (WTChangeOrder2) reference.getObject();
						QueryResult qr2 = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeNotice, false);
						

						while (qr2.hasMoreElements()) {
							ChangeRecord2 record = (ChangeRecord2) qr2.nextElement();
							Changeable2 changeable = record.getChangeable2();
							System.out.println("Branch :" + changeable.getBranchIdentifier());

							ReferenceFactory rf2 = new ReferenceFactory();
							WTReference changeablereference = (WTReference) rf2.getReference(changeable);
							
							if (changeable instanceof WTPart) {
								
								System.out.println("WTPartMaster is found");
								WTPart part = (WTPart) changeablereference.getObject();

								PersistableAdapter obj = new PersistableAdapter(part, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
								obj.load("MaterialSpec");

								String MaterialSpecValue = (java.lang.String) obj.get("MaterialSpec");
								
								System.out.println("MaterialSpec: " + MaterialSpecValue);

								if (MaterialSpecValue != null) {
									System.out.println("MaterialSpec: " + MaterialSpecValue);
								} else {
									System.out.println("Material Spec is null");
								}
							}
						}
					}
				}
				catch(Exception exception) {
					exception.printStackTrace();
				}

View solution in original post

3 REPLIES 3

Are you looking for a mapping of an alias attribute, or do you need to retrieve it attribute via api, or some other way?

No Alias attribute. I want to pass one attribute value to the sap, for that in my code  i am getting the change notice number in which the part is involved in the change notice. So i am having the change notice number, by using the Change notice number  i want to retrieve the part, after the  retrieving i want to retrieve the part attribute.

 

ReferenceFactory rf = new ReferenceFactory();
WTReference reference = (WTReference) rf.getReference(changeNumber);
WTChangeOrder2 changeNotice = (WTChangeOrder2) reference.getObject();

QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeNotice, false);
System.out.println("After size: " + qr.size());

while (qr.hasMoreElements()) {
ChangeRecord2 record = (ChangeRecord2) qr.nextElement();
Changeable2 changeable = record.getChangeable2();
Persistable objMaster = changeable.getMasterReference().getObject();
QueryResult qr1 = ConfigHelper.service.filteredIterationsOf(objMaster, new LatestConfigSpec());
if (objMaster instanceof WTPart) {
WTPart part = (WTPart) objMaster;

// Assuming that PersistableAdapter's constructor takes these parameters
PersistableAdapter adapter = new PersistableAdapter(part, null, SessionHelper.getLocale(), null);
adapter.load("MATERIAL_TYPE");

Object materialTypeValue = adapter.get("MATERIAL_TYPE");
System.out.println("MaterialTypeValue: " + materialTypeValue);

if (materialTypeValue != null) {
materialType = materialTypeValue.toString();
System.out.println("Material Type: " + materialType);
} else {
System.out.println("Material Type is null");
}
}

Give it a try this way

				try {
					
					QuerySpec qs = new QuerySpec(WTChangeOrder2.class);
					
					SearchCondition searchcondition = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.NUMBER, SearchCondition.EQUAL, "CN0007698");
					

					qs.appendWhere(searchcondition, new int[]{0});
					final QueryResult qr = PersistenceHelper.manager.find(qs);
					while (qr.hasMoreElements()) {
						WTChangeOrder2 ecn = (WTChangeOrder2) qr.nextElement();
						System.out.println(" Found Change Order Number: " + ecn.getNumber());
						
						ReferenceFactory rf = new ReferenceFactory();
						WTReference reference = (WTReference) rf.getReference(ecn);
						WTChangeOrder2 changeNotice = (WTChangeOrder2) reference.getObject();
						QueryResult qr2 = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeNotice, false);
						

						while (qr2.hasMoreElements()) {
							ChangeRecord2 record = (ChangeRecord2) qr2.nextElement();
							Changeable2 changeable = record.getChangeable2();
							System.out.println("Branch :" + changeable.getBranchIdentifier());

							ReferenceFactory rf2 = new ReferenceFactory();
							WTReference changeablereference = (WTReference) rf2.getReference(changeable);
							
							if (changeable instanceof WTPart) {
								
								System.out.println("WTPartMaster is found");
								WTPart part = (WTPart) changeablereference.getObject();

								PersistableAdapter obj = new PersistableAdapter(part, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
								obj.load("MaterialSpec");

								String MaterialSpecValue = (java.lang.String) obj.get("MaterialSpec");
								
								System.out.println("MaterialSpec: " + MaterialSpecValue);

								if (MaterialSpecValue != null) {
									System.out.println("MaterialSpec: " + MaterialSpecValue);
								} else {
									System.out.println("Material Spec is null");
								}
							}
						}
					}
				}
				catch(Exception exception) {
					exception.printStackTrace();
				}
Announcements

Top Tags