Action on part itemtype

Hi,

 i need to set up a functionality upon on clicking Action in Part item, it should create three parts for me with three different X class values and three documents with three different X class values has to be create . 

Example: 

Action on Part item 

PART  A has to be created with X class 'ABC'

Document A has to be created with X class '123'

Document A has to be linked to PART A(Files to the document item will be added by user later)

PART B has to be created with X class 'DEF'

Document B has to be created with X class '456'

Document B has to be linked to PART B(Files to the document item will be added by user later)

PART C has to be created with X class 'XYZ

Document C has to be created with X class '789'

Document C has to be linked to PART C(Files to the document item will be added by user later)

When ever i trigger this action, above process has to happen.

Any Suggestions how to implement this ?

  • Hi Prakash

    Create an Action  Type = "Item" Location = "Server" and add below method in that. 

    Innovator inn = this.getInnovator();
    var lockStatus = this.getLockStatus();
    var currentCheck = this.getProperty("is_current", "0");
    // Hard Coded Item Count and ID of xClass
    var countNum = 3
    string[] partxClass = new string[] { "PXClassID1", "PXClassID2", "PXClassID3"};
    string[] documentxClass = new string[] { "DXClassID1", "DXClassID2", "DXClassID3"};
    if (lockStatus != 1)
    {
    return inn.newError("Part must be locked to perform this action. Please lock and proceed.");
    }
    if (currentCheck != "1")
    {
    return inn.newError("Part must be latest generation to perform this action. Please select the latest generation of this Part.");
    }
    for( int i = 0; i < countNum; i++ )
    {
    // Input : ID of the Part xClass
    Item newPart = inn.newItem("Part", "add");
    Item xClassPart = newPart.createRelationship("Part_xClass", "add");
    //ID of the corresponding Part xClass
    xClassPart.setProperty("related_id", partxClass[i]);
    newPart = newPart.apply();
    if (!newPart.isError())
    {
    // Input : ID of the Document xClass
    Item newDocument = inn.newItem("Document", "add");
    newDocument.setProperty("name", "Document");
    //Document Number is mandatory and form a unique sequence based on your requirement
    newDocument.setProperty("item_number", "Document" + i);
    Item xClassDocument = newDocument.createRelationship("Document_xClass", "add");
    //ID of the corresponding Document xClass
    xClassDocument.setProperty("related_id", documentxClass[i]);
    Item newRelationship = inn.newItem("Part Document", "add");
    newRelationship.setAttribute("doGetItem", "0");
    newRelationship.setProperty("source_id", newPart.getID());
    newRelationship.setRelatedItem(newDocument);
    newRelationship = newRelationship.apply();
    if (newRelationship.isError())
    {
    return newRelationship;
    }
    }
    }
    return inn.newResult("Created Part and Document Successfully.");

    Open Part Item Type and add this action under Actions tab

    Thanks

    Gopikrishnan R