Maximo Open Forum

 View Only

 Automation Script to copy one field to another

  • Administration
jordan l's profile image
jordan l posted 08-28-2024 09:41

I have been dabbling in writing an automation script to pull assetmeter.remarks into a comments field under the measurement table.  The script is a based on a object launch point on the measurement table and triggered by a save even with add? checked.  The issue is that the script seems to reflect on the front end, but does not commit to the database.

Matt F's profile image
Matt F

Hey Jordan,

Just to confirm my understanding, you want these ASSETMETER.REMARKS entries copied to the MEASUREMENT table after a Meter Reading has been entered on an Asset, correct?

If so, I believe you'd want this to be triggered on the ASSETMETER table/object, rather, being that MEASUREMENT is your destination. I'd setup a Save Event ASSETMETER object launch point, or a Run Action Event REMARKS attribute launch point. 

Let me know how you progress!

Cheers,

jordan l's profile image
jordan l

@Matt F That is correct, I have tried what you mentioned, but I am getting the same results, the field is being copied over to the measurement.comments field in the UI, but I do not see the value saved to the database.  To expand on the steps taken:

1) I created a relationship from the AssetMeter table to the Measurement table

2) Create a Automation Script, with an object launchpoint, save event, on add & update and setting to after commit

3) Script variables are remarks (binded to remarks) and comments (binded to measurement.comments)

4) Script reads as:

if remarks is not none:
comments = remarks

Matt F's profile image
Matt F

This worked for me as a Run Action Attribute Launch Point Script (ASSETMETER.REMARKS). 

Let me know how you make out.

from psdi.mbo import MboConstants

def main():
    # Ensure the mbo is not None and is based on the ASSETMETER object
    if mbo is not None and mbo.isBasedOn("ASSETMETER"):
        # Check if the REMARKS attribute has been updated
        if mbo.isModified("REMARKS"):
            # Get the updated remarks value from the ASSETMETER object
            remarks = mbo.getString("REMARKS")

            # Retrieve the related MEASUREMENT MboSet
            measurement_set = mbo.getMboSet("MEASUREMENT")
            measurement = measurement_set.moveFirst()

            # Loop through each MEASUREMENT Mbo in the set
            while measurement is not None:
                # Update the COMMENTS field in the MEASUREMENT table
                measurement.setValue("COMMENTS", remarks, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION)

                # Move to the next measurement in the set
                measurement = measurement_set.moveNext()

            # Close the MboSet to free resources
            measurement_set.close()

main()


Cheers,

Travis Herron's profile image
Travis Herron

Love it @Matt F! This thread has inspired me to take on another scripting project much like that of the OP here -- to take a Work Order's Status Change Memo and copy it to that same Work Order's Work Log.