Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Creating ChangeNotices with Java SOA Libraries

Experimenter
Experimenter

Hi all,

We have to create ChangeNotices (or maybe Change Items) on TC from the data which is handed to us from another application. It might not sound intuitive to use Chane Management like this, but at the moment all we need to do is:

1- Get data from outside

2- Extract the information we need to fill properties of CN to be created

3- Get ItemID and create the item.

Basically all we need is to make the "HelloTeamcenter" sample project to work with ChangeNotice-Type instead of Item-Type.

We have already managed to get ItemIDs and RevIDs (ECN-xxx), create input data and send it via the createItem, but there are some problems.

Questions: 

Q1- Can we use the "normal"  DMService , CreateItem and ItemProperties? or we should rather go for ServiceManagementService, CreateChangeItemInputs and createChangeItems?

Q2- According to documentation, the second option with createChangeItems is deprecated and createObjects should be used instead. Indeed we could only make it work, but only sporadically (interestingly, just the first item gets created, then the program aborts with "some programming error" message).

Q3- Wehre should the "Description" property be set on a ChangeNotice/ChangeItem for this error message:

    Code: 39032	Severity: 3	The operation input descriptor "ChangeNoticeCreI" requires a value for the property "Description" for business objects of type "Change Notice".

It has driven me mad in the last few days and deadline is looming, so any help will be highly appreciated.

Thanks!

15 REPLIES 15

Re: Creating ChangeNotices with Java SOA Libraries

Siemens Phenom Siemens Phenom
Siemens Phenom

Q1- Can we use the "normal"  DMService , CreateItem and ItemProperties? or we should rather go for ServiceManagementService, CreateChangeItemInputs and createChangeItems?

 

I would use the normal DataManagementService createObjects, or createRelateAndSubmitObjects2.

 

Q2- According to documentation, the second option with createChangeItems is deprecated and createObjects should be used instead. Indeed we could only make it work, but only sporadically (interestingly, just the first item gets created, then the program aborts with "some programming error" message).

 

 If you still get the error then it would be helpful to post a minimalistic example that shows the error so we can diagnose.

 

Q3- Wehre should the "Description" property be set on a ChangeNotice/ChangeItem for this error message:

 

The Description property is object_desc, and it is mandatory for the ChangeNotice Item.

If you look in BMIDE at the create descriptor of ChangeNotice then you can see that object_desc has its required constant set to true;

 

000200.jpg

 

 

Here's a minimalistic snippet of Java that successfully creates a ChangeNotice on my system;

// The create input for the ChangeNotice Item
DataManagement.CreateInput itemCreateIn = new DataManagement.CreateInput();
itemCreateIn.boName = "ChangeNotice";
itemCreateIn.stringProps.put("item_id", "ECN-100000");
itemCreateIn.stringProps.put("object_name", "Name of ECN-100000");
itemCreateIn.stringProps.put("object_desc", "Description of ECN-100000");


// The create input for the ChangeNoticeRevision
DataManagement.CreateInput revisionCreateIn = new DataManagement.CreateInput();
revisionCreateIn.boName = "ChangeNoticeRevision";
revisionCreateIn.stringProps.put("item_revision_id", "A");


// Tie the Revision CreateInput to the Item CreateInput
itemCreateIn.compoundCreateInput.put("revision", new DataManagement.CreateInput[]{revisionCreateIn});

// The data for the createObjects call
DataManagement.CreateIn cnCreateIn = new DataManagement.CreateIn();
cnCreateIn.clientId = "Create ECN-10000";
cnCreateIn.data = itemCreateIn;

DataManagement.CreateResponse createResponse = dmService.createObjects(new DataManagement.CreateIn[]{cnCreateIn});
if (createResponse.serviceData.sizeOfPartialErrors() > 0) {
    logErrors(createResponse.serviceData);
}
else {
    for (DataManagement.CreateOut createOut : createResponse.output) {
        logger.info("Response for client ID " + createOut.clientId);
        for (ModelObject modelObject : createOut.objects) {
            logger.info("Created Object " + modelObject.getTypeObject().getName() + " : " + modelObject.getUid());
        }
    }
}

 

On my system the log output looks like the follwing;

CreateObjectsTest - Logging in as user
CreateObjectsTest - Logged in
CreateObjectsTest - Response for client ID Create ECN-10000
CreateObjectsTest - Created Object ChangeNotice : w5OAAEuO4TRQUD
CreateObjectsTest - Created Object ChangeNotice Master : w9AAAEuO4TRQUD
CreateObjectsTest - Created Object ChangeNoticeRevision : w9GAAEuO4TRQUD
CreateObjectsTest - Logging out
CreateObjectsTest - Logged out

 

 

If you want to use createRelateAndSubmit2 then here's a snippet that creates an Item (not a CN, but you can adapt it), adds it into the users home folder, then launches the default workflow on the new revision;

 

DataManagement.CreateIn2 createIn2 = new DataManagement.CreateIn2();
createIn2.clientId = "CreateObject1";

// The Item Data
createIn2.createData = new DataManagement.CreateInput2();
createIn2.createData.boName = "Item";
createIn2.createData.propertyNameValues.put("item_id", new String[]{item_id});
createIn2.createData.propertyNameValues.put("object_name", new String[]{"Name of " + item_id});
createIn2.createData.propertyNameValues.put("object_desc", new String[]{"Desc of " + item_id});


// The ItemRevision Data
DataManagement.CreateInput2 revCreate = new DataManagement.CreateInput2();
revCreate.boName = "ItemRevision";
revCreate.propertyNameValues.put("item_revision_id", new String[]{revision_id});
revCreate.propertyNameValues.put("object_name", new String[]{"Name of " + item_id + "/" + revision_id});

// Tie the ItemRevision create data into the Item create data
createIn2.createData.compoundCreateInput.put("revision", new DataManagement.CreateInput2[]{revCreate});

// Paste the new revision into the users home folder
createIn2.pasteProp = "contents";
createIn2.targetObject = user.get_home_folder();

// Submit the ItemRevision to the workflow defined in the <type>_default_workflow_template pref.
// By default this is going to be
// WorkspaceObject_default_workflow_template = WorkspaceObjectDefaultWorkflowTemplate
createIn2.workflowData.put("submitToWorkflow", new String[]{"true"});

com.teamcenter.services.strong.core._2008_06.DataManagement.CreateResponse createResponse = dmService.createRelateAndSubmitObjects2(new DataManagement.CreateIn2[]{createIn2});
if (createResponse.serviceData.sizeOfPartialErrors() > 0) {
    logErrors(createResponse.serviceData);
}
else {
    for (com.teamcenter.services.strong.core._2008_06.DataManagement.CreateOut createOut : createResponse.output) {
        logger.info("Created Objects for clientId " + createOut.clientId);
        for (ModelObject object : createOut.objects) {
            logger.info("Created " + object.getTypeObject().getName() + " : " + object.getUid());
        }
    }
}

 

When you have the revision you should be able to use calls such as createRelations to add problem items.

 

Hopefully this helps.

Re: Creating ChangeNotices with Java SOA Libraries

Experimenter
Experimenter

WOW! Thank you! Thank you very much. Exactly what I was looking for. Actually I had only read the email notification until now and that was enough for a breakthrough. The hint with "object_desc" was exactly what I was looking for, but I couldn't manage to find item_revision_id property name, which was of course normal because I wasn't creating the revision. One point though: according to the documentation, createObject should be recursive. So, this has worked for me with this code

CreateIn[] inputPropsEcn = new CreateIn[numberOfItems];
for (int i = 0; i < numberOfItems; i++) {
CreateIn inputProperty = new CreateIn();
main.FunctionBlock component = componentsList.get(i);
CreateInput createInputs = new CreateInput();
Map<String, String> propertyValueMapping = new HashMap<String, String>();

String description = "Removed FunctionBlock " + component.getName();
propertyValueMapping.put("item_id", itemIds[i].newItemId);
propertyValueMapping.put("object_desc", description);
createInputs.boName = itemType;
createInputs.stringProps = propertyValueMapping;
inputProperty.clientId = TCSession.CLIENT_ID;
inputProperty.data = createInputs;
inputPropsEcn[i] = inputProperty;
}

//inputPropsEcn will be sent to TC

 I can see the CN revision / rev. master items listed in change home, but not the CN master itself. I'm not sure if this is the right thing because I've actually completely new to this world. Another point: by searching the itemID I can find the change notice and CN master.

 

Capture.PNG

 

 

Maybe there is something missing on my BMIDE, since it is not a very nice and clean installation. I can't find ChangeNotice at all.

 

The hint about createRelations was also very good. I was looking for a function which does it. How and where can I find a good documentation or some examples? The HTML one in soa_library.zip does not have enough infomration, well at least for someone like me.

 

It did indeed help and I'm very grateful for that. 

Mahyar

Re: Creating ChangeNotices with Java SOA Libraries

Siemens Phenom Siemens Phenom
Siemens Phenom

The recursive bit of the createInputs is where you can for example add the CreateInput for the revision, or item master form to the CreateInput for the item.  You can see this in my code where I have ...

// Tie the Revision CreateInput to the Item CreateInput
itemCreateIn.compoundCreateInput.put("revision", new DataManagement.CreateInput[]{revisionCreateIn});

The compoundCreateInput permits us to add additional child CreateInputs to the parent.  This can go down more than one level, so you can have Item -> ItemRevision -> ItemRevision Master Form for example.

 

 

Change Home normally displays change object revisions so what you are seeing is expected.

 

It seems that your BMIDE project is not set up with the full set of templates that you have installed into your Teamcenter.  If you select your project, then pick Project -> Properties from the menu then you should be able to get to a BMIDE screen like the following.  Make sure you have selected the templates that you need, and that are installed into your Teamcenter.

 

000206.jpg

 

 

Working with createRelation is actually fairly straightforward.

You need to know the ModelObject for each end of the relation, and the relation type.

So to add a problem item to a change notice revision the relation type is CMHasProblemItem.

Your code would look a bit like...

DataManagement.Relationship[] relations = new DataManagement.Relationship[1];
relations[0] = new DataManagement.Relationship();
relations[0].primaryObject = theECNRevision;
relations[0].secondaryObject = theProblemObject;
relations[0].relationType = "CMHasProblemItem";
DataManagement.CreateRelationsResponse createRelationsResponse = dmService.createRelations(relations);
if (createRelationsResponse.serviceData.sizeOfPartialErrors() > 0) {
    // TODO We got an error when we tried to create the relationship
}

 

You do need to be aware that the ability to create relationships to change objects is controlled by a set of conditions so you can only add certain relations when the change object is in a particular state.

This is covered in the documentation;  in the BMIDE Guide there is a chapter "Configure Teamcenter Applications" that has a section on Change Management, and the Change Manager Guide has details on administering the change process and how to control which actions may be performed in which states.

Re: Creating ChangeNotices with Java SOA Libraries

Experimenter
Experimenter

Thanks again Jonathan.

I think I have jumped into the middle of it and because of that, I don't understand some things.

Firstly, by using your code with compoundCreateInput every component was create twice, so I switched back to my code. As I said, CN master and master revision get created with that one too. 

 

Secondly, what are model objects which are to be related in 

relations[0].primaryObject = theECNRevision;
relations[0].secondaryObject = theProblemObject;

 I can't understand the primary and secondary objects. Are they for example Items and ItemRevisions? 

Main problem is like this: create CN, relate an item to Problem under the CN. The item is inside a folder under newstuff. How can I get the item? I assumed something like

ModelObject mo = "get object with item id function"(itemID)

or 

ModelObject mo = "query item"(itemID)

Is it possible in any way? For instance I know I have a detector with itemID/name "00027/A;1-WPDetector". Just want it to appear under problemItem of "ECN-00010"

 

Thanks again.

Re: Creating ChangeNotices with Java SOA Libraries

Siemens Phenom Siemens Phenom
Siemens Phenom

For a relation the primary is the "from" end and the secondary is the "to" end.

For a problem item relationship the from end will be the ChangeNoticeRevision that you just created.

The to end is the object that is the problem.  In you case it's the ItemRevision 00027/A.

There are several ways to get an ItemRevision if you know some information about it.

If you know an item id and a revision id then you can use DataManagementService getItemAndRelatedObjects a bit like the following;

    /**
     * Finds the ItemRevision object for a specified item_id and item_revision_id
     *
     * @param item_id  The item_id
     * @param item_rev The item_revision_id
     * @return The matching ItemRevision or null if not found
     */
    private ItemRevision findItemRevision(final String item_id, final String item_rev) {
        LOG.info("Finding Item Rev ... (ID=" + item_id + "/" + item_rev + ")");

        ItemRevision itemRevision = null;
        try {
            DataManagement.GetItemAndRelatedObjectsInfo findItemRevInfo[] = new DataManagement.GetItemAndRelatedObjectsInfo[1];
            findItemRevInfo[0] = new DataManagement.GetItemAndRelatedObjectsInfo();
            findItemRevInfo[0].clientId = item_id;
            findItemRevInfo[0].itemInfo = new DataManagement.ItemInfo();
            findItemRevInfo[0].itemInfo.ids = new DataManagement.AttrInfo[1];
            findItemRevInfo[0].itemInfo.ids[0] = new DataManagement.AttrInfo();
            findItemRevInfo[0].itemInfo.ids[0].name = "item_id";
            findItemRevInfo[0].itemInfo.ids[0].value = item_id;
            findItemRevInfo[0].itemInfo.useIdFirst = true;

            findItemRevInfo[0].revInfo = new DataManagement.RevInfo();
            findItemRevInfo[0].revInfo.processing = "Ids";
            findItemRevInfo[0].revInfo.nRevs = 1;
            findItemRevInfo[0].revInfo.id = item_rev;

            findItemRevInfo[0].datasetInfo = new DataManagement.DatasetInfo();
            findItemRevInfo[0].datasetInfo.filter = new DataManagement.DatasetFilter();
            findItemRevInfo[0].datasetInfo.filter.processing = "None";
            findItemRevInfo[0].datasetInfo.namedRefs = new DataManagement.NamedReferenceList[0];

            DataManagement.GetItemAndRelatedObjectsResponse findItemRev = dmService.getItemAndRelatedObjects(findItemRevInfo);

            itemRevision = findItemRev.output[0].itemRevOutput[0].itemRevision;
            if (itemRevision != null) {
                LOG.info("Got ItemRevision " + itemRevision.get_item_id() + "/" + itemRevision.get_item_revision_id());
            }
        }
        catch (NotLoadedException e) {
            LOG.error(e);
        }
        return itemRevision;
    }

If you know the item id, and want the latest revision then you can change

 

            findItemRevInfo[0].revInfo = new DataManagement.RevInfo();
            findItemRevInfo[0].revInfo.processing = "Ids";
            findItemRevInfo[0].revInfo.nRevs = 1;
            findItemRevInfo[0].revInfo.id = item_rev;

to

 

            findItemRevInfo[0].revInfo = new DataManagement.RevInfo();
            findItemRevInfo[0].revInfo.processing = "Nrev";
            findItemRevInfo[0].revInfo.nRevs = 1;

You can also use revision rules if you need something like the latest released.

 

 

There are also other alternatives like running saved queries, or navigating folders.

Re: Creating ChangeNotices with Java SOA Libraries

Experimenter
Experimenter

It worked perfectly, thank you. Unfortunately there is now another problem: Changing circumstances of the project. Now that we have decided to use itemIDs of components we use in our library, there will be some changes there, hence the itemIDs will not remain the same but the names do. So it seems that there is no other choice but switching to query with item name . It is not an elegant idea to query for each and every item, but I don't see any way around at the moment. (maybe to query a whole set of data/items?)

So it's now a mix of query to find the objects in library and retrieving the newly created CN objects, then creating a relation between them. I think I leave it for the moment at that. 

Very grateful for your help and surely I will ask for more in the future ;)

Re: Creating ChangeNotices with Java SOA Libraries

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

Hello All, 

This is a helpful conversation for creating an ECN through SOA library. However , my requirement is to fetch the existing ECN and its afffected, solution items from teamcenter. here I already have below attributes

  1. itemRevUID: wbexkEQCJQQC0C
  2. item_id: ECN-000001
  3. item_revision_id: A
  4. object_desc: HS_ECN1_DESCRIPTION
  5. object_name: HS_ECN1_SYNOPSIS
  6. object_type: Change Notice Revision

Your help is highly appriciated.

Re: Creating ChangeNotices with Java SOA Libraries

Siemens Phenom Siemens Phenom
Siemens Phenom

It looks like you already have the UID of the ChangeNoticeRevision you are interested in so you have a couple of options;

 

Use the core DataManagementService loadObjects method to get the ModelObject for your change notice.

It'll be in the plainObjects part of the ServiceData.

From there you could use core DataManagementService expandGRMRelationsForPrimary to expand the relations you are interested in, and retrieve the ItemRevisions at the other end.  You should be able to expand both relations in a single call.

 

Alternatively you could still use loadObjects, and after some checks cast the resulting object to a ChangeNoticeRevision.

This object has get_CMImpactedItems and get_CMSolutionItems methods which return ModelObject arrays.

 

Either way you will either need to setup your ObjectPropertyPolicy in advance, or use DataManagementService getProperties to retrieve properties from the returned objects.

 

Note that if you didn't have the UID, but only the item_id, or item_id and item_revision_id you could still get the ChangeNoticeRevision using DataManagementService getItemAndRelatedObjects as shown earlier in the thread.

 

 

Re: Creating ChangeNotices with Java SOA Libraries

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

Thanks Jonathan for your help.

 

I have decided to go with checking if(mObj instanceof ChangeNoticeRevision), as that is inline with rest of the code to identify exact objects. Can you please help in importing a particular package and soa_client jar file to include in which I can find ChangeNoticeRevision Type ? At present my eclipse is not able to recognize ChangeNoticeRevision class.

 

Your help is much appriciated.