Wednesday 14 December 2016

SOA Service Client : Global Alternate

How to add/remove Global Alternate using SOA Service?
Before answering please understand please visit What is Global Alternate?

//Consider modObj1 ->part to which global alternate is to be added
//Consider modObj2 -> Alternate part
//Alternate part can  be multiple
How to Add Global Alternate
private static void addRelatedGlobalAlternates(ModelObject modObj1, ModelObject modObj2)
{

 Item primaryPart = (Item) modObj1;
 Item[] alternatePartArr = new Item[1];
 alternatePartArr[0] = (Item) modObj2;

     // Call the Service to add alternate

 GlobalAlternateListInput globalAlternateListInput = new GlobalAlternateListInput();

 globalAlternateListInput.gAltItems = alternatePartArr;
 globalAlternateListInput.item = primaryPart;

        GlobalAlternateListInput[] globalAlternateListInputArr = new GlobalAlternateListInput[1];
 globalAlternateListInputArr[0] = globalAlternateListInput;

 // GlobalAlternateService is from package com.teamcenter.services.internal.strong.structuremanagement
 GlobalAlternateService globalAlternateService = GlobalAlternateService.getService(connection);
 GlobalAlternateResponse globalAlternateresponse = globalAlternateService.addRelatedGlobalAlternates(globalAlternateListInputArr);
}


How to Remove Global Alternate
private static void removeRelatedGlobalAlternates(ModelObject modObj1, ModelObject modObj2)

    {

        Item primaryPart = (Item) modObj1;
        Item[] alternatePartArr = new Item[1];
        alternatePartArr[0] = (Item) modObj2;

       // Call the Service to delete alternate
        GlobalAlternateListInput globalAlternateListInput = new GlobalAlternateListInput();
        globalAlternateListInput.gAltItems = alternatePartArr;
        globalAlternateListInput.item = primaryPart;

        GlobalAlternateListInput[] globalAlternateListInputArr = new GlobalAlternateListInput[1];
        globalAlternateListInputArr[0] = globalAlternateListInput;

        GlobalAlternateService globalAlternateService = GlobalAlternateService.getService(connection);
        GlobalAlternateResponse globalAlternateresponse = globalAlternateService.removeRelatedGlobalAlternates(globalAlternateListInputArr);
    }

1 comment:

  1. Is there any APIs that return preferred Global Alternate Item?
    GlobalAlternate.PreferredGlobalAlternateInput is use to set the prefer global alternate. But there is no class or method that return preferred global alternate item.

    ReplyDelete