Diksha
Diksha

Reputation: 11

How to create link between parts in windchill throgh API

How to create link between part and document in windchill through API. I have tried the following code.

WTPartDescribeLink wl=WTPartDescribeLink.newWTPartDescribeLink(part1, Doc1);
PersistenceHelper.manager.save(wl);

but its not working.:(:(

Upvotes: 0

Views: 7746

Answers (2)

chance
chance

Reputation: 6507

You do not need to check out the document and part before creating a link between them. (If you do in that way, new iterations are generated only for adding the link - this is probably not acceptable in many cases).

Instead, try to insert the created link on the server side like this:

PersistentObjectManager.getPom().insert(WTCollection, null, null);

or

PersistenceServerHelper.manager.insert(WTCollection);

On client side, use RemoteMethodServer to invoke server-side code:

RemoteMethodServer.getDefault().invoke(...);

Upvotes: 1

Vignesh Vino
Vignesh Vino

Reputation: 1238

You need to check out both the WTDocument,WTPart objects and take the working copy after that you have to pass.

Below is the working code to create a WTPartDescribeLink

import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.folder.Folder;
import wt.part.WTPart;
import wt.part.WTPartDescribeLink;
import wt.pds.StatementSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import wt.vc.wip.CheckoutLink;
import wt.vc.wip.WorkInProgressHelper;

public class PartDesc {

    public static void main(String args[]) throws WTException, WTPropertyVetoException
    {
        WTPart part=null;
        WTDocument doc=null;
        String number="0000000025";
        String docnumber="0000000027";
        QuerySpec qspec=new QuerySpec(WTPart.class);
        qspec.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,number),new int[]{0,1});
        QueryResult qr=PersistenceHelper.manager.find((StatementSpec)qspec);
        while(qr.hasMoreElements())
        {
            part=(WTPart) qr.nextElement();
        }
        System.out.println("Part found");

        QuerySpec qspec1=new QuerySpec(WTDocument.class);
        qspec1.appendWhere(new SearchCondition(WTDocument.class,WTDocument.NUMBER,SearchCondition.LIKE,docnumber),new int[]{0,1});
        QueryResult qr1=PersistenceHelper.manager.find((StatementSpec)qspec1);
        while(qr1.hasMoreElements())
        {
            doc=(WTDocument) qr1.nextElement();
        }
        System.out.println("Document found");

          //Checkout and getting Working copy of object
        Folder checkoutFolder = WorkInProgressHelper.service.getCheckoutFolder();
        CheckoutLink col = WorkInProgressHelper.service.checkout(doc,checkoutFolder,"");
        doc = (WTDocument)col.getWorkingCopy();


        Folder checkoutFolder1 = WorkInProgressHelper.service.getCheckoutFolder();
        CheckoutLink col1 = WorkInProgressHelper.service.checkout(part,checkoutFolder,"");
        part = (WTPart)col1.getWorkingCopy();

        //Creating Link between part and doc
        WTPartDescribeLink link=WTPartDescribeLink.newWTPartDescribeLink(part, doc);
        PersistenceHelper.manager.save(link);
        System.out.println("link created ");

        doc = (WTDocument)WorkInProgressHelper.service.checkin(doc,"");
        part = (WTPart)WorkInProgressHelper.service.checkin(part,"");
    }

}

Upvotes: 1

Related Questions