Maximo

Maximo

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

 View Only
  • 1.  Change WO's ASSETNUM via autoscript?

    Posted Fri June 26, 2020 03:16 PM
    Edited by System Admin Wed March 22, 2023 11:49 AM
    I'm attempting to change a WO's ASSETNUM via an automation script (Maximo 7.6.1.1).

    The specific line I'm trying to use is:

    woMbo.setValue("assetnum", assetnum)

    But I'm getting an error that says I can't edit the asset field:

    {"oslc:Error":{"oslc:statusCode":"400","errorattrname":"assetnum","spi:reasonCode":"BMXAA0019I","correlationid":null,"oslc:message":"BMXAA0019I - The Asset field is either read only or part of the primary key. You cannot edit this field.","oslc:extendedError":{"oslc:moreInfo":{"rdf:resource":"http:\/\/myURL\/maximo\/oslc\/error\/messages\/BMXAA0019I"}}}}

    Is there a way to edit the ASSETNUM in a workorder via an automation script?




    Full script: UPDATEWOASSETNUM
    #URL:
    #http://server:host/maximo/oslc/script/UPDATEWOASSETNUM?_lid=wilson&_lpwd=wilson&wonum=LWO0280&assetnum=LA1234
    #
    from psdi.server import MXServer
    from psdi.mbo import MboSet
    from psdi.mbo import MboConstants

    resp = {}
    wonum = request.getQueryParam("wonum")
    assetnum = request.getQueryParam("assetnum")

    woset = MXServer.getMXServer().getMboSet("workorder",request.getUserInfo())
    whereClause = "wonum= '" + wonum + "'"
    woset.setWhere(whereClause)
    woset.reset()
    woMbo = woset.moveFirst()

    #If workorder already exists, update it:
    if woMbo is not None:
    woMbo.setValue("assetnum", assetnum)
    woset.save()
    woset.clear()
    woset.close()
    resp[0]='Updated workorder ' + wonum

    responseBody =resp[0]



    ------------------------------
    Thanks
    ------------------------------
    #Maximo
    #AssetandFacilitiesManagement


  • 2.  RE: Change WO's ASSETNUM via autoscript?

    Posted Fri June 26, 2020 04:10 PM
    This seems to work, although I have no idea why.

    woMbo.setValue("assetnum", assetnum, 11L)

    ------------------------------
    Thanks
    ------------------------------



  • 3.  RE: Change WO's ASSETNUM via autoscript?

    Posted Sat June 27, 2020 11:02 AM
    Hi ,

    11L signifies the MboConstants value.
    MboConstant is an Interface which is commonly used to Suppress field methods .
    Below url gives details about use of mboconstants.
    http://maximowave.blogspot.com/2012/10/mbo-constants-in-maximo.html

    In your case, 11L - Suppress field Validaton, Action and Access check.

    Asset field must be set as readonly on the UI therefore you were getting an error earlier but with the use of 11L, readonly is supressed and thus you are not getting the error.

    ------------------------------
    Biplab Choudhury
    Maximo Consultant
    Tata Consultancy Services
    Melbourne
    ------------------------------



  • 4.  RE: Change WO's ASSETNUM via autoscript?

    Posted Mon June 29, 2020 03:40 AM
    Hi
    My first advice is stick to OOTB - Maximo is designed for good reason! What is the unique business requirement that is demanding changing the WO asset number by not following the OOTB ?

    ------------------------------
    Kevin Elliott
    ------------------------------



  • 5.  RE: Change WO's ASSETNUM via autoscript?

    Posted Mon June 29, 2020 08:13 AM

    Strongly second Kevin's response. If the field is read-only the work order is in a status that doesn't allow the asset to be changed. Maximo has the concept of edit rules (configured in the Organization application) which control when certain attributes (such as Asset) are allowed to be modified on a WO. These rules are evaluated both interactively in the UI and through any background process (automation script/cron task/escalation). These can be adjusted if necessary, but out of box only allow it to be modified in a WAPPR status.

    There are a couple of reasons for this. If a technician has done work on asset 1 and you change the work order to asset 2, that means work was done on the wrong asset. Someone reviewing it after the fact will think maintenance was done on the proper asset but it might never have been. In those cases it tends to be better to create a new work order rather than change the asset. Another one most aren't aware of is if you recorded any actuals, these costs won't be properly rolled up to the asset costs if the asset is changed after they're recorded. These transactions record the asset at the time of the transaction and then when the roll up occurs it matches that asset to the work order asset and if it doesn't match, it gets ignored. 

    If you decide you need to allow these adjustments, I would recommend trying to use 2L (or MboConstants.NOACCESSCHECK if you import MboConstants from psdi.mbo) over 11L. Suppressing validation & action eliminate quite a few checks that you would want to occur. NOACCESSCHECK ignores the read-only aspect, but otherwise all other logic is evaluated. 



    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 6.  RE: Change WO's ASSETNUM via autoscript?

    Posted Mon June 29, 2020 10:22 AM
    I fully agree with Steven. What you need to do is find out why it's read-only.

    The first thing to do is to check the history flag, which can be set by canceling or closing the work order.

    If that flag is cleared, then you check the status. Use the WOSTATUS synonym domain to convert your WO's status to its internal value. Then go to the Organizations application and see whether the edit settings for work orders for that organization allow the asset to be changed during that internal status.

    If the last two checks tell you that your work order's asset should be allowed to change, then you have probably made some business rules of your own that aren't being satisfied. So, you need to go check out the Global Data Restrictions in the Security Groups app, and check out security group specific data restrictions that apply to your user. And, if you still can't figure it out, go look at your object or attribute launch points and their automation scripts.

    Someone mentioned the UI, but you're hitting a script via the REST API, so the UI (beans, lookups, etc) are not applicable.

    On a slightly different note, I strongly suggest you look at the Maximo 7.6.0.9 JavaDocs which you can get to from the Maximo APIs and SDKs page. In particular, you can find the different setValue() methods on psdi.mbo.Mbo and the psdi.mbo.MboConstants class which has the flags that Biplab and Steven referred to.

    ------------------------------
    Blessings,
    Jason Uppenborn
    Sr. Technical Maximo Consultant
    Ontracks Consulting
    ------------------------------



  • 7.  RE: Change WO's ASSETNUM via autoscript?

    Posted Mon June 29, 2020 11:18 AM
    Following this thread and my first gut response is "Why?"  Why are you changing the asset number on a work order? Why are you doing this through an automation script? What action is triggering the Automation Script.  But then I thought "Meh... so many of these tech forums are just looking for a technical solution they have either already figured out the business reasons and they have settled on the business need and now just need a technical solution, OR they just don't really care about the business requirements and are just looking to get a technical solution regardless of the validity.  

    Then I read Kevin, Steven and Jason's posts.  
    So to fully support and echo their statements, the business requirement MUST be evaluated. If the technical solution is in alignment with the business rules then all is well.  However this technical issues suggests that is not the case.

    As Steven remarks the WPEDIT rules in the organization applicaiton govern the edibility of a variety of fields depending upon status.  So if you are getting an MBO validation error and you bypass that validation check you may very well be doing something incorrect as both Steven and Jason point out.  Further, child transactions which carry the asset number associated to the work order, will indeed accrue costs to the asset (and location). If you change the asset number on the work order and do not also update (or at least validate the location is still correct for the asset) then you have disconnected the transactions form the work order.  

    Another issue you may or may not be addressing/ glossing over is the asset/ location relationship.  If you change the asset number on the location and you do not validate the location value, are you addressing it in some other way?  Does the location (which you may or may not be addressing on the work order) have multiple assets? is the issue you are trying to resolve one in which the work order was created and set correctly at the location level but the wrong asset was chosen?  Will you logic address this such that if there is only one asset at the location and you try to change it will your scripting address this and warn the user ?

    ------------------------------
    Bradley K. Downing , MBA
    IBM Certified Adv. Deployment Prof. Maximo v7.6.1
    IBM
    Bakersfield CA
    ------------------------------



  • 8.  RE: Change WO's ASSETNUM via autoscript?

    Posted Mon June 29, 2020 11:36 AM
    Edited by System Admin Wed March 22, 2023 11:47 AM

    Thanks, everyone for your input. Some great points have been made.


    In my case, I'm just making a rough proof-of-concept for doing a one-time data load into the demo database/environment (via the Mike Wilson user). So in that case, I think the scenario is pretty low risk. But I agree that there would be lots more to consider if the script was not a one-time-only operation and performed in a live environment.

    Cheers.



    ------------------------------
    Thanks
    ------------------------------