Maximo Open Forum

 View Only

 How to implement similar functionality like allornothing header from bulk update in a simple automation script

  • Customizations
Rana Ahmed's profile image
Rana Ahmed posted 10-22-2024 21:53

I came across this feature in Maximo bulk update API.
IBM Maximo REST API Guide – Bulk operations
which is called allornothing header. When this value is set to 1. Maximo if any of the updates failed in that packet. It rolls back all the changes.

I was wondering how can I implement something like this in an automation script. Not related to an API call just normal automation script.

e.g.

I want to write a similar function in an automation script which will update workorder description. If it is unable to update any of the workorder. It should be able to continue to save or rollback based on allornothing parameter passed in function. I have written a starter script but not sure how can I implemented that sort of save

def updateWO(allornothing):
    mx = MXServer.getMXServer()
    wo_set = mx.getMboSet("WORKORDER", mx.getSystemUserInfo())
    wo_set.setWhere("...")
    wo_set.reset()
    wo = wo_set.moveFirst()
    while wo:
        wo.setValue("DESCRIPTION", "ABC")
        # If there is any error in setting the description value e.g. record is already closed

    #if allornothing:
    #    wo_set.save()
    # save if any of the workorder threw an error.
Prajesh Pradhananga's profile image
Prajesh Pradhananga
def updateWO(allornothing):
    mx = MXServer.getMXServer()
    wo_set = mx.getMboSet("WORKORDER", mx.getSystemUserInfo())
    wo_set.setWhere("...")  # Your specific where clause here
    wo_set.reset()
    wo = wo_set.moveFirst()
    has_error = False

    while wo:
        try:
            # Attempt to set the description value
            wo.setValue("DESCRIPTION", "ABC")
        except MXException as e:
            has_error = True
            if allornothing:
                # If all-or-nothing, stop further updates and break out
                break
            else:
                # Log or handle the error for this specific work order
                print(f"Failed to update work order {wo.getString('WONUM')}: {str(e)}")
        
        # Move to the next work order in the set
        wo = wo_set.moveNext()

    if allornothing:
        if has_error:
            wo_set.rollback()  # Rollback if any errors occurred
            print("Rolled back all changes due to an error.")
        else:
            wo_set.save()  # Save only if no errors occurred
    else:
        # Save all successful changes regardless of errors
        wo_set.save()
        print("Saved all successfully updated work orders.")

    # Cleanup the MboSet
    wo_set.close()