Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
Expand all | Collapse all

Need Autoscript help

  • 1.  Need Autoscript help

    Posted Tue November 19, 2024 07:28 AM

    In the workorder table I created a field called PAYBYPCARD and it is defined in Maximo as a yes/no field

    When a workorder is saved, I need that field to be evaluated to see if it has been checked.  If it has been checked I need workorder to require 3 other fields to be filled out.

    Python script

    #PAIDBYPCARD SCRIPT

    if PAYBYPCARD == 1:

       PCARDAMOUMT=True

       PCARDHOLDER=True

       PCARDPAIDDATE=True

     

    I also tried this version:

    #PAIDBYCARD SCRIPT

    if PAIDBYPCARD == 'YES':

       pcardamount_required=True

       pcardholder_required=True

       pcardpaiddate=True

    When activated it is giving me a boolean java language exception if I check mark the field

    Any assistance is greatly appreciated



    ------------------------------
    Paul Bishop
    ------------------------------


  • 2.  RE: Need Autoscript help

    Posted Tue November 19, 2024 07:56 AM

    Here is a script that launches off the init and action of the PAIDBYCARD attribute.

    It includes the scriptConfig so you can deploy it with the VS Code extension:

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

    Let me know if you have any questions.

    Regards,

    Jason

    from psdi.mbo import MboConstants
    
    def main():
        # If this is called in the context of a work order Mbo save and the PAIDBYPCARD field is true, then make the additional fields required.
        if 'mbo' in globals() and mbo.isBasedOn("WORKORDER") and mbo.getBoolean("PAIDBYPCARD"):                
            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, True)
            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, True)
            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, True)
        else:
            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, False)
            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, False)
            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, False)
    
    main()
    
    scriptConfig="""{
        "autoscript": "WORKORDER.SAVE",
        "description": "Make additional fields required if a p-card is used.",
        "version": "",
        "active": true,
        "logLevel": "ERROR",
        "scriptLaunchPoints": [
            {
                "launchPointName": "WORKORDER.PAIDBYPCARD.INIT",
                "launchPointType": "ATTRIBUTE",
                "active": true,
                "description": "Evaluate if additional fields should be required on initialization",
                "objectName": "WORKORDER",
                "attributeName": "PAIDBYPCARD",
                "initializeValue": true  
            } ,
            {
                "launchPointName": "WORKORDER.PAIDBYPCARD.ACTION",
                "launchPointType": "ATTRIBUTE",
                "active": true,
                "description": "Evaluate if additional fields should be required when PAIDBYPCARD is checked or unchecked",
                "objectName": "WORKORDER",
                "attributeName": "PAIDBYPCARD",
                "runAction": true  
            }        
        ]    
    }"""


    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 3.  RE: Need Autoscript help

    Posted Tue November 19, 2024 09:12 AM

    I'm getting 2 errors



    ------------------------------
    Paul Bishop
    ------------------------------



  • 4.  RE: Need Autoscript help

    Posted Tue November 19, 2024 09:14 AM

    This works on Run Action and Init.  The Run Action evaluates when you change the value and the Init evaluates when the record is opened so it ensures that the fields are made read-only on init and whenever the checkbox is updated.

    Do you have any details on what those errors are?

    Jason



    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 5.  RE: Need Autoscript help

    Posted Tue November 19, 2024 09:22 AM

    The first red x says Missing ";" beforer statement

    The second Red x says 

    expected 'from' and instead saw 'def'.
    expected '(string)' and instead saw 'main'.
    expecting semicolon.

    unrecoverable syntax error (7% scanned)



    ------------------------------
    Paul Bishop
    ------------------------------



  • 6.  RE: Need Autoscript help

    Posted Tue November 19, 2024 09:35 AM

    Hi Paul,

    Without seeing what you are seeing, it is hard to guess what is wrong. Based your initial example I wrong this in jython and your error about semicolons and formatting errors, perhaps you have selected Javascript / Nashorn. 

    If you are using Jython, be aware that spaces are significant and copy / pasting from these discussion forums can mess with the formatting. For reference here is a screenshot of the code in the Maximo editor.  

    Regards,
    Jason



    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 7.  RE: Need Autoscript help

    Posted Tue November 19, 2024 10:06 AM

    I appreciate the help.
    This is where I am at right now.

    It is not erroring, but it is also not doing anything.  When I check the box and click save, it just saves and moves on with the required fields not filled in.

    Note, that I had provided you an invalid field name, so I updated the script to the correct field name


    This is the script:

    from psdi.mbo import MboConstants

    def main():
        # If this is called in the context of a work order Mbo save and the PAYBYPCARD field is true, then make the additional fields required.
        if 'mbo' in globals() and mbo.isBasedOn("WORKORDER") and mbo.getBoolean("PAYBYPCARD"):                
            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, True)
            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, True)
            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, True)
        else:
            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, False)
            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, False)
            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, False)

    main()

    scriptConfig="""{
        "autoscript": "WORKORDER.SAVE",
        "description": "Make additional fields required if a p-card is used.",
        "version": "",
        "active": true,
        "logLevel": "ERROR",
        "scriptLaunchPoints": [
            {
                "launchPointName": "WORKORDER.PAYBYPCARD.INIT",
                "launchPointType": "ATTRIBUTE",
                "active": true,
                "description": "Evaluate if additional fields should be required on initialization",
                "objectName": "WORKORDER",
                "attributeName": "PAYBYPCARD",
                "initializeValue": true  
            } ,
            {
                "launchPointName": "WORKORDER.PAYBYPCARD.ACTION",
                "launchPointType": "ATTRIBUTE",
                "active": true,
                "description": "Evaluate if additional fields should be required when PAYBYPCARD is checked or unchecked",
                "objectName": "WORKORDER",
                "attributeName": "PAYBYPCARD",
                "runAction": true  
            }        
        ]    
    }"""


    Setup 

    Launch Point



    ------------------------------
    Paul Bishop
    ------------------------------



  • 8.  RE: Need Autoscript help

    Posted Tue November 19, 2024 10:12 AM

    You will need two Attribute launch points, one on PAYBYPCARD Initialize and one on PAYBYPCARD on Run Action.  Your launch point is currently on before save. 



    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 9.  RE: Need Autoscript help

    Posted Tue November 19, 2024 10:24 AM

    I don't see an option for adding a launchpoint.  I see where I can activate/deactivate a launchpoint, but not how to add more than one.



    ------------------------------
    Paul Bishop
    ------------------------------



  • 10.  RE: Need Autoscript help

    Posted Tue November 19, 2024 10:55 AM

    Paul,

    It seems that you might be missing some foundational concepts of automation scripts and launch points.  I recommend that you reach out to one of the Maximo integrators for more formal assistance in this regard.

    The IBM documentation is a good place to start, but you may still want to engage an expert for a more in depth explanation and assistance.

    Here is a good reference to start in the interim.

    https://ibm-maximo-dev.github.io/maximo-autoscript-documentation

    Regards,
    Jason



    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 11.  RE: Need Autoscript help

    Posted Fri November 22, 2024 12:58 PM

    Hey Jason

     

    I appreciate your support and the references.

     

    I got 2 attribute launch points set up on the field PAYBYPCARD.

     

    One is an initialize launchpoint and the other is a run.

     

    The initialize is throwing an error on creation of a new workorder.

     

    Everything works great when editing an existing workorder

     

    Any ideas you have would be greatly appreciated.

     

     

     

     

    from psdi.mbo import MboConstants

     

    def main():

        # If this is called in the context of a work order Mbo save and the PAYBYPCARD field is true, then make the additional fields required.

        if 'mbo' in globals() and mbo.isBasedOn("WORKORDER") and mbo.getBoolean("PAYBYPCARD"):                

            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, True)

            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, True)

            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, True)

            mbo.setFieldFlag("GLACCOUNT",MboConstants.REQUIRED, False)

     

        else:

            mbo.setFieldFlag("PCARDAMOUMT",MboConstants.REQUIRED, False)

            mbo.setFieldFlag("PCARDHOLDER",MboConstants.REQUIRED, False)

            mbo.setFieldFlag("PCARDPAIDDATE",MboConstants.REQUIRED, False)

            mbo.setFieldFlag("ARIBAORDERNUM",MboConstants.REQUIRED, False)

            mbo.setFieldFlag("OBLIGATIONNUM",MboConstants.REQUIRED, False)

       

    main()

     

    scriptConfig="""{

        "autoscript": "WORKORDER.SAVE",

        "description": "Make additional fields required if a p-card is used.",

        "version": "",

        "active": true,

        "logLevel": "ERROR",

        "scriptLaunchPoints": [

            {

                "launchPointName": "WORKORDER.PAYBYPCARD.INIT",

                "launchPointType": "ATTRIBUTE",

                "active": true,

                "description": "Evaluate if additional fields should be required on initialization",

                "objectName": "WORKORDER",

                "attributeName": "PAYBYPCARD",

                "initializeValue": true 

            } ,

            {

                "launchPointName": "WORKORDER.PAYBYPCARD.ACTION",

                "launchPointType": "ATTRIBUTE",

                "active": true,

                "description": "Evaluate if additional fields should be required when PAYBYPCARD is checked or unchecked",

                "objectName": "WORKORDER",

                "attributeName": "PAYBYPCARD",

                "runAction": true 

            }       

        ]   

    }"""

     

     

    Thanks

     

    Paul D Bishop (Contractor)
    Maximo Development Team Lead

    Logo  Description automatically generated

    Supporting A/PRI/TI

    Department of State

    Maximo Support Email FMSMAXIMO@state.gov

    Bishoppd1@state.gov

    paul.bishop@navitastech.com

    703-244-3706