Maximo Open Forum

 View Only
  • 1.  Limit number of levels in classification hierarchy

    Posted 12-17-2021 01:31
    Edited by User 1972 12-17-2021 10:14
    MAM 7.6.1.2:

    What would be a good way of limiting the number of levels in a classification hierarchy?

    For example, limit the number of classification levels to four.

    A \ B \ C \ D \ E --> produce error when user tries to create classification E.


    Thanks.
    #Administration

    ------------------------------
    User 1972
    ------------------------------


  • 2.  RE: Limit number of levels in classification hierarchy

    Posted 12-17-2021 10:25
    Edited by User 1972 12-22-2021 15:26
    I came up with something that seems to work.


    Create a relationship:


    Parent Object: CLASSSTRUCTURE
    Relationshiop: CGCLASSANCESTOR_PARENTTOPLEV
    Child Object: CLASSANCESTOR
    
    Where Clause:
    classstructureid=:parent
    order by hierarchylevels desc
    fetch first row only
    
    Remarks:
    Relationship to the classancestor table. Used to find the classstructure's *parent* top-level ancestor. The resulting set will contain zero or *one* objects.​




    Create an automation script:
    Object launch point. Object: CLASSSTRUCTURE. Save. Add/Update. Before Save.

    errorMsg = """
    "You can't create a classification with more than four levels. This is an xyz-specific restriction. 
    \n Automation script name: CGCLASSSTRUCTUREHIERARCHYPATH."
    """
    
    #Note: CLASSANCESTOR.HIERARCHYLEVELS starts at 0, not 1. 
    #      So if there are "3" HIERARCHYLEVELS, then that means there are actually 4 levels.
    if mbo.getInt("CGCLASSANCESTOR_PARENTTOPLEV.HIERARCHYLEVELS") > 2: #Notice that the relationship points to the classstructure's *parent*.
        service.error("", errorMsg)

    Note: I'm aware that I should make a proper Maximo error message, instead of putting the error message text in the script. This is just a proof-of-concept.