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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Windchill 10.2 : Cannot find newly added attributes by using attributeContainer.getAttributeDefinitions()

ptc-5407164
1-Newbie

Windchill 10.2 : Cannot find newly added attributes by using attributeContainer.getAttributeDefinitions()

I just created a new global attribute (att1) and added it to an existing classification (classifX). Now I cant find that attribute within the classification attributes. My code looks like this:

ClassificationNode cNode = queryForClassificationNodeByName("classifX");
cNode
= (ClassificationNode)IBAValueHelper.service.refreshAttributeContainer(cNode, "CSM", null, null);
DefaultAttributeContainer attributeContainer = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();
AttributeDefDefaultView views[] = attributeContainer.getAttributeDefinitions();
for (int lv = 0; lv < views.length; lv++) {
AbstractValueView avv[] = attributeContainer.getAttributeValues(views[lv]);
for(int i = 0; i < avv.length; i++){
System.out.println(avv[i].getDefinition().getName());
}
}

I get all the other attributes but not the attribute I just created. Could any one please tell me what's missing?

3 REPLIES 3

You can try this method

/**

* Method to populate the attribute information for Classification attributes.

* @param currNode

* @return

* @throws RemoteException

* @throws WTException

*/

public static Map<String,String> getWCAttribInfo((ClassificationNode currNode) throws RemoteException, WTException

{

Map<String,String> attribInfo = new TreeMap<String,String>();

IBAHolder[] ibaHolder = IBAValueHelper.service.refreshAttributeContainer(new IBAHolder[]{(IBAHolder)currNode});

for (int i=0; i<ibaHolder.length; i++) {

// Do something with values[i], such as print it

System.out.println("IBAHolder ==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+ ibaHolder[i] );

}

DefaultAttributeContainer attribContainer = (DefaultAttributeContainer) currNode.getAttributeContainer();

// System.out.println("attribcontainer ==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+ attribContainer );

// DefaultAttributeContainer attribContainer = (DefaultAttributeContainer) ibaHolder[0].getAttributeContainer();

System.out.println("attribcontainer ==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + currNode.getName() + " --> " + attribContainer);

if(attribContainer != null)

{

AttributeDefDefaultView[] attributes = attribContainer.getAttributeDefinitions();

System.out.println("No of attributes for this node: ==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + attributes.length);

for(int i=0;i<attributes.length;i++)

{

AttributeDefDefaultView attrib = attributes[i];

System.out.println("Attribute name: ==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + attrib.getName());

AbstractValueView[] attribValue = attribContainer.getAttributeValues(attrib);

String strAttribValue = ""; //initialize with a ~

if(attribValue != null && attribValue.length > 0)

{

System.out.println("==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

for(int j=0;j<attribValue.length;j++)

{

if(j==0)

{

strAttribValue = strAttribValue + IBAValueUtility.getLocalizedIBAValueDisplayString(attribValue[j], Locale.getDefault());

}

else

{

strAttribValue = strAttribValue + ";" + IBAValueUtility.getLocalizedIBAValueDisplayString(attribValue[j], Locale.getDefault());

}

}

System.out.println("Attribute value:==============================================>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + strAttribValue);

attribInfo.put(attrib.getName(), strAttribValue);

}

// //Moving this line to outside the if block, as the db structure also needs to include the attributes that do not have a value

// //specified..

attribInfo.put(attrib.getName().trim(), strAttribValue.trim());

}

}

return attribInfo;

}

Let me know your results

Thank you Ramakrishna. In fact I already solved this issue but forgot to tag it as solved.

Anyway, I implemented a solution in the same spirit as this one.

Thanks again.

you are welcome Rihad,

Do you have some insight on fetching the metadata of the attribute using WC Customization.

"How to fetch the metadata of an attribute or for all attributes for a given WCType using Windchill customization?

Steps for more information

  1. Create a subType of Complaint object
  2. Create some attributes for the subtype 3. Now i need to write customization to fetch the attributes and the attribute's metadata

for Eg : I have an attribute "BSCAwareness" on the Complaint subtype I need to fetch the default values, constraints , datatype etcc....

Let me know if you need more information


Top Tags