Maximo Open Forum

 View Only
  • 1.  Automation scripts.

    Posted 05-08-2023 02:31

    I want to know that step by step using automation scripts that if priority is greater than 6 and line type= Material, set remark field of PR line as 'emergency pr' when pr gets approved. if priority is less than 6 and line type is 'material' set remark field of pr line as 'normal pr' when pr gets approved.


    #EverythingMaximo

    ------------------------------
    Gaurav Sharma
    ------------------------------


  • 2.  RE: Automation scripts.

    Posted 05-09-2023 11:06

    OK so I would run that on an object launch point on Update - Before Save

    if mbo.isModified('STATUS') and mbo.getString('STATUS')=='APPR':
      if mbo.getInt('PRIORITY')>6:
        mbo.setValue('REMARKS','Emergency PR', mbo.NOACCESSCHECK)
      else:
        mbo.setValue('REMARKS','Normal PR', mbo.NOACCESSCHECK)


    ------------------------------
    David Shaw
    Peacocks Engineering Ltd
    ------------------------------



  • 3.  RE: Automation scripts.

    Posted 05-09-2023 11:54

    Gaurav,

    David's answer is partially correct, but please note that he references the PR and not the PRLINE as you requested, it doesn't check for the PRLINE LINETYPE and it is the "REMARK" attribute and not "REMARKS" so if you were to use this unfortunately it would not work for you.

    Below is a complete script for you that does what you are requesting by looking at the status of the PR and then looping through the PRLINES and setting the line remark attribute. I have also included the scriptConfig variable so you can directly deploy this using the VS Code Maximo Dev Tools extension:

    https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy

    If you have any questions please feel free to reach out.

    Jason

    from psdi.mbo import MboConstants
    
    def main():
        # Make sure that this script wasn't accidentally triggered by another launch point.
        # Make sure you are dealing with the expected Mbo type. (Note that this is PR not PR line)
        if mbo is not None and mbo.isBasedOn("PR"):
            # Use the getInternalStatus() method to get the current status of the PR to include synonyms of Approved.
            # Check that the Status attribute was modified so this doesn't get called multiple times.
            if mbo.getInternalStatus() == "APPR" and mbo.isModified("STATUS"):
                # it is high priority if the priority is greater than 6
                highPriority = mbo.getInt("PRIORITY") > 6
    
                # Get the PR lines
                prLineSet =mbo.getMboSet("PRLINE")
                prLine = prLineSet.moveFirst()
    
                while prLine is not None:
                    if prLine.getString("LINETYPE") == "MATERIAL":
                        # When the PR is approved the line becomes read only so we are using the MboConstants.NOACCESSCHECK flag to allow writing.
                        # https://www.sharptree.io/blog/2022/2022-01-03-mbo-constants/
                        prLine.setValue("REMARK", "Emergency PR" if highPriority else "Normal PR", MboConstants.NOACCESSCHECK)
    
                    prLine = prLineSet.moveNext()
    
    main()
    
    scriptConfig="""{
        "autoscript": "PRLINE.REMARKS",
        "description": "Set PR Line Remarks on Approve",
        "version": "",
        "active": true,
        "logLevel": "ERROR",
        "scriptLaunchPoints": [
            {
                "launchPointName": "PRLINE.REMARKS",
                "launchPointType": "OBJECT",
                "active": true,
                "description": "Set PR Line Remarks on Approve",
                "objectName": "PR",
                "save": true,
                "add": false,
                "update": true,
                "delete": false,
                "beforeSave": true
            }
        ]
    }"""


    ------------------------------
    Jason VenHuizen
    Sharptree
    ------------------------------