Tuesday 13 December 2016

SOA Service client:Get Object by UIDs

Sometimes for testing purpose you require object from TC
How to get object from TC when you have UID ?

1) Create method as below method name depends on you
2) 1- parameter  ->Array Of UIDs for which you want Teamcneter objects
   2- parameter ->Teamcenter connection object
3)Must Read comment
Note: Provided sample code include some extra code which you may/may not require

public static ModelObject[] getModelObjectsFromUIDs(String[] arrayOfUIDs, Connection connection)
{

         ModelObject[] arrModelObjects = null;

         if (arrayOfUIDs.length > 0)
        {
           ArrayList<ModelObject> modelObjects =
          new ArrayList<ModelObject>(arrayOfUIDs.length);
             
        //This Class is from  com.teamcenter.services.strong.core package
             DataManagementService dataManagementService = DataManagementService.getService(connection);  
      //This API require array of UIDs only  
     //This will load objects and provide you as ServiceData plainobjects
ServiceData loadObjects = dataManagementService.loadObjects(arrayOfUIDs);
          for (int i = 0; i < loadObjects.sizeOfPlainObjects(); i++)            {                   //Collect all the objects for given  UIDs in array list                modelObjects.add(loadObjects.getPlainObject(i));             }            if (modelObjects != null && modelObjects.size() > 0)            {                 //Java method to convert array list to array                 arrModelObjects = modelObjects.toArray(new ModelObject[0]);       }      }        return arrModelObjects;    }

Explanation : Important API
ServiceData loadObjects = dataManagementService.loadObjects(arrayOfUIDs);

2 comments:

  1. why is dataManagementService.loadObjects(arrayOfUIDs); throwing an error on loadObjects and asking if I've missed an assembly reference?

    ReplyDelete
  2. how do you get the UID of a NX part?

    ReplyDelete