Forum Discussion

Kai_Kircher's avatar
Kai_Kircher
Ideator I
5 years ago
Solved

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):

[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:c6adf788-e399-4db7-b63a-90e953d6ebf3:type=csharp&text=Innovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0AItem%20myResult%3B%0D%0Aif%20%28this.getProperty%28%22classification%22%2C%20%22%22%29%20%3D%3D%20%22Hull%20Assembly%22%20%26%26%20this.isRoot%28%29%20%3D%3D%20true%29%0D%0A%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2Femail%20code%0D%0A%7D%0D%0Areturn%20this%3B%0D%0A%0D%0A%0D%0A%2F%2For%0D%0A%0D%0A%0D%0AInnovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0AItem%20myResult%3B%0D%0Aif%20%28this.getProperty%28%22classification%22%2C%20%22%22%29%20%3D%3D%20%22Hull%20Assembly%22%20%26%26%20this.getParentItem%28%29%20%3D%3D%20null%29%0D%0A%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2Femail%20code%0D%0A%7D%0D%0Areturn%20this%3B%0D%0A%0D%0A%0D%0A%0D%0A%2F%2For%0D%0A%0D%0A%0D%0AInnovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0AItem%20myResult%3B%0D%0Aif%20%28this.getProperty%28%22classification%22%2C%20%22%22%29%20%3D%3D%20%22Hull%20Assembly%22%20%26%26%20this.getProperty%28%22source_id%22%2C%20%22%22%29%20%3D%3D%20%22%22%29%0D%0A%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2Femail%20code%0D%0A%7D%0D%0Areturn%20this%3B]

  • 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

2 Replies

  • 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