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);
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);
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.");