What is the best way to validate whether an item has a parent?

I'm trying to send an email on promotion to "Released" of Parts when a couple of criteria are met, the parts being of a certain custom classification we've added, and them not being used in another BOM anywhere (i.e. they're top-level Parts being released).

What's the best way to go about checking whether the part is a top-level part (i.e. doesn't have a parent)? I've tried isRoot(), getParentItem(), and getProperty("source_id"), but I'm either misusing those or for some reason they're not working for my case.

This is what I have tried so far (this method is attached as a Post method to the lifecycle transitions to Released, and it is generating the emails, it's just not limiting it to only the times when it's a top-level BOM, like I want):

Innovator inn = this.getInnovator();
Item myResult;
if (this.getProperty("classification", "") == "Hull Assembly" && this.isRoot() == true)
{
        //email code
}
return this;


//or


Innovator inn = this.getInnovator();
Item myResult;
if (this.getProperty("classification", "") == "Hull Assembly" && this.getParentItem() == null)
{
        //email code
}
return this;



//or


Innovator inn = this.getInnovator();
Item myResult;
if (this.getProperty("classification", "") == "Hull Assembly" && this.getProperty("source_id", "") == "")
{
        //email code
}
return this;

Parents
  • Hi Kai Kircher

    Easiest way to check whether the item is top level item or not, you can use below code

    Innovator inn = this.getInnovator();
    Item myResult;
    if (this.getProperty("classification", "") == "Hull Assembly")
    {
    Item checkIsRoot = this.newItem("Part BOM","get");
    checkIsRoot.setAttribute("select","id");
    checkIsRoot.setAttribute("maxRecords","1");
    checkIsRoot.setProperty("related_id",this.getID());
    checkIsRoot = checkIsRoot.apply();
    if(checkIsRoot.isError())
    {
    //email code
    }
    else
    {
    // This item has been used in some Part as BOM
    }
    }
    return this;

    Thank You

    Gopikrishnan R

Reply
  • Hi Kai Kircher

    Easiest way to check whether the item is top level item or not, you can use below code

    Innovator inn = this.getInnovator();
    Item myResult;
    if (this.getProperty("classification", "") == "Hull Assembly")
    {
    Item checkIsRoot = this.newItem("Part BOM","get");
    checkIsRoot.setAttribute("select","id");
    checkIsRoot.setAttribute("maxRecords","1");
    checkIsRoot.setProperty("related_id",this.getID());
    checkIsRoot = checkIsRoot.apply();
    if(checkIsRoot.isError())
    {
    //email code
    }
    else
    {
    // This item has been used in some Part as BOM
    }
    }
    return this;

    Thank You

    Gopikrishnan R

Children