Maximo

 View Only
Expand all | Collapse all

Creating new asset with script

  • 1.  Creating new asset with script

    Posted Mon October 17, 2022 10:14 AM
    Hello!

    I need to create child assets  (some 5 with these same descriptions in each case) for asset with specific Description (whenever it is created under some existing assets)

    Core script without some specific checking (f.i. if particular childes are already present) looks like this

    aktSet = mbo.getMboSet("ASSET_ASSET")
    aktSet.reset()
    jAkt = aktSet.add()
    jAkt.setValue("DESCRIPTION","Jauns pases aktīvs")
    jAkt.setValue("ASSETTYPE","RAA")
    jAkt.setValue("PARENT","100000237366")
    jAkt.setValue("LOCATION","10000062")
    
    aktSet.save()
    aktSet.celar()
    aktSet.close()​

    I have all mandatory fields, but is showing error message 
    BMXAA4195E - A value is required for the Asset field on the ASSET object.

    Don't understand, what is really missing, which field?

    Thank You!

    ------------------------------
    Juris Flugins
    ------------------------------



    #Maximo
    #AssetandFacilitiesManagement
    #MaximoIntegrationandScripting


  • 2.  RE: Creating new asset with script

    IBM Champion
    Posted Mon October 17, 2022 10:33 AM
    Hello Juris - You are missing many required fields for example- SITEID in the script.

    Kindly make sure you are setting value in all required fields before saving the MboSet.

    Thanks.

    ------------------------------
    Prashant Sharma
    Maximo Solution Architect
    ------------------------------



  • 3.  RE: Creating new asset with script

    Posted Tue October 18, 2022 12:05 AM
    Hello, but when I add siteid, I get error, that that is system field, which I should not change. 

    But, if really script in general looks OK, I will try to add some other fields, which are marked as REQUIRED in database configuration for ASSET table.
    But they are some 51, and most of them seems really unnecessary, even some looks like fileds, which are populated during asset lifecycle.

    Maybe You know what really is minimal set of attributes?
    I already added ORGID, but that is not enough.

    ------------------------------
    Juris Flugins
    ------------------------------



  • 4.  RE: Creating new asset with script

    Posted Tue October 18, 2022 01:23 AM
    Got to point, where I added ITEMSETID field, and had no error, but I don't see that asset in system. 

    aktSet = mbo.getMboSet("ASSET_ASSET")
    aktSet.reset()
    jAkt = aktSet.add()
    jAkt.setValue("DESCRIPTION","Jauns pases aktīvs")
    jAkt.setValue("ASSETTYPE","RAA")
    jAkt.setValue("PARENT","100000237366")
    jAkt.setValue("LOCATION","10000062")
    jAkt.setValue("ORGID","ASTORG")
    jAkt.setValue("DISABLED","0")
    jAkt.setValue("ISLINEAR","0")
    jAkt.setValue("ISRUNNING","1")
    jAkt.setValue("MXASTYPE","RAA")
    jAkt.setValue("ITEMSETID","ASIS")
    
    aktSet.save()
    aktSet.celar()
    aktSet.close()​


    ------------------------------
    Juris Flugins
    ------------------------------



  • 5.  RE: Creating new asset with script

    Posted Tue October 18, 2022 01:25 AM
    Strange, I noticed that I have
    aktSet.celar()​

    not clear
    after that I got again the same error. Will continue adding fields.



    ------------------------------
    Juris Flugins
    ------------------------------



  • 6.  RE: Creating new asset with script

    Posted Tue October 18, 2022 02:32 AM
    I added all fields, which in DB by default doens't has NULL value. Then I commented out fields, which scipt execution told, that are some key fileds, which system only should change, at the end, I got again that message, that something is still missing. I'm afraid, that my code is not correct

    aktSet = mbo.getMboSet("ASSET_ASSET")
    aktSet.reset()
    jAkt = aktSet.add()
    jAkt.setValue("DESCRIPTION","Jauns pases aktīvs")
    jAkt.setValue("ASSETTYPE","RAA")
    jAkt.setValue("PARENT","100000237366")
    jAkt.setValue("LOCATION","10000062")
    jAkt.setValue("ORGID","ASTORG")
    jAkt.setValue("DISABLED","0")
    jAkt.setValue("ISLINEAR","0")
    jAkt.setValue("ISRUNNING","1")
    jAkt.setValue("MXASTYPE","RAA")
    jAkt.setValue("ITEMSETID","ASIS")
    jAkt.setValue("PURCHASEPRICE","0")
    jAkt.setValue("REPLACECOST","0")
    #jAkt.setValue("TOTALCOST","0")
    #jAkt.setValue("YTDCOST","0")
    jAkt.setValue("BUDGETCOST","0")
    #jAkt.setValue("UNCHARGEDCOST","0")
    #jAkt.setValue("TOTUNCHARGEDCOST","0")
    #jAkt.setValue("TOTDOWNTIME","0")
    #jAkt.setValue("INVCOST","0")
    jAkt.setValue("DISABLED","0")
    jAkt.setValue("AUTOWOGEN","0")
    #jAkt.setValue("MAINTHIERCHY","0")
    jAkt.setValue("MOVED","0")
    jAkt.setValue("HASLD","0")
    jAkt.setValue("ISLINEAR","0")
    jAkt.setValue("RETURNEDTOVENDOR","0")
    jAkt.setValue("EXPECTEDLIFE","0")
    jAkt.setValue("TLOAMPARTITION","0")
    jAkt.setValue("PLUSCISCONTAM","0")
    jAkt.setValue("PLUSCISINHOUSECAL","0")
    jAkt.setValue("PLUSCISMTE","0")
    jAkt.setValue("PLUSCPMEXTDATE","0")
    jAkt.setValue("PLUSCSOLUTION","0")
    jAkt.setValue("ISCALIBRATION","0")
    jAkt.setValue("PLUSDPRIMARYIND","0")
    jAkt.setValue("PLUSDHAVESAMPLEWO","0")
    jAkt.setValue("PLUSDNEEDSAMPLEWO","0")
    jAkt.setValue("MXASISVIRTUAL","0")
    jAkt.setValue("PLUSSISGIS","0")
    
    
    aktSet.save()
    aktSet.clear()
    aktSet.close()​


    ------------------------------
    Juris Flugins
    ------------------------------



  • 7.  RE: Creating new asset with script

    Posted Tue October 18, 2022 02:46 AM
    Hi Juris,
    From the original message it appears that ASSETNUM is missing.
    Have you tried adding it?

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 8.  RE: Creating new asset with script

    Posted Tue October 18, 2022 02:52 AM
    Yes, I also tried ASSETNUM, but got error, that this is key fied, that system can only change. 

    Maybe that relationship is not correct for the context? It is

    assetnum=:assetnum and siteid=:siteid

    ------------------------------
    Juris Flugins
    ------------------------------



  • 9.  RE: Creating new asset with script

    Posted Tue October 18, 2022 03:42 AM
    Maybe... How is the relationship created?
    And I'm not sure why you would need a relationship.
    Have you tried simply aktSet = mbo.getMboSet("ASSET")?

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 10.  RE: Creating new asset with script

    Posted Tue October 18, 2022 04:16 AM
    Because that name there is relationship, and by default there is no relationship in with name ASSET for table ASSET. If there is no relationship, then there is approach with were clause.

    ------------------------------
    Juris Flugins
    ------------------------------



  • 11.  RE: Creating new asset with script

    Posted Tue October 18, 2022 04:21 AM
    Hmmm... not sure what to try more.
    Have you checked this?:
    https://bportaluri.com/wp-content/downloads/MaximoAutomationScriptsQuickReference.pdf

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 12.  RE: Creating new asset with script

    Posted Tue October 18, 2022 04:46 AM
    Of course. Hoped someone had some working exapmle here for some bussiness case to create asset woth script. 
    Tried different things. 
    I also added on save, that 11L -> save(11L) so it doesn't do validation, but it still trows that error.

    ------------------------------
    Juris Flugins
    ------------------------------



  • 13.  RE: Creating new asset with script

    Posted Tue October 18, 2022 04:56 AM
    Try to use generateAutoKey() to have the value for ASSETNUM generated by the system.
    Something like:
    ...
    jAkt = aktSet.add()
    jAkt.generateAutoKey()
    jAkt.setValue("DESCRIPTION","Jauns pases aktīvs")
    ...

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 14.  RE: Creating new asset with script

    Posted Tue October 18, 2022 05:27 AM
    I tried this before in different form, inside setValue for assetnum, but this way it helped somehow :) Thank You!
    as I'm geting now different message

    BMXAA0089E - Asset 100000255234 is not a valid asset.

    And each time I press button (to run script for test purposes), that assetnum un increasing. So something is happening. 
    I also tried to move that row after all steValue. The same error. 
    Will check, maybe there are just too much setValue now, and there is some conflict, as also some of those values should be still set by system.

    ------------------------------
    Juris Flugins
    ------------------------------



  • 15.  RE: Creating new asset with script

    Posted Tue October 18, 2022 05:29 AM
    I suppose, maybe I need to somehow get that new assetnum (just don't know how), which is generated, get that entry from DB, and then set values.

    ------------------------------
    Juris Flugins
    ------------------------------



  • 16.  RE: Creating new asset with script

    Posted Tue October 18, 2022 05:34 AM
    Each time the script is run generateAutoKey() is incrementing the value for assetnum.
    Anyway, it looks like you are on the right track. :)
    Try to add just the mandatory fields (assetnum, siteid, description etc.) until you get the proper asset record; then you can add the rest of them (e.g. parent).
    Good luck!

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 17.  RE: Creating new asset with script

    Posted Tue October 18, 2022 08:29 AM
    When I put some valid (next) assetnum in assetnr, I can create new asset. 
    When I have like this
    aktSet = mbo.getMboSet("ASSET_ASSET");
    aktSet.reset();
    jAkt = aktSet.add();
    assetnr = jAkt.getMboValue("ASSETNUM").autoKey()
    jAkt.setValue("ASSETNUM",assetnr,11L)
    
    jAkt.setValue("DESCRIPTION","Jauns pases aktīvs");
    jAkt.setValue("ASSETTYPE","RAA");
    jAkt.setValue("PARENT","100000237366");
    jAkt.setValue("LOCATION","10000062");
    
    aktSet.save();
    aktSet.clear();
    aktSet.close();​
    I first get that errror, which says, that asset with (next number) is incorrect asset, and after that, that first error
    According to this https://www.maximotimes.com/forum/general-maximo-7-support/asset-autonumer-not-generated-when-creating-record-from-automation-script/
    or that jAkt.generateAutoKey() should have worked. But no.
    Or I added them to code incorrrectly (I tried many variations, also autokey is not accepting attributes, tried to put it at the end etc) ?
    Or, there is some error or misconfiguration in my environment?

    ------------------------------
    Juris Flugins
    ------------------------------



  • 18.  RE: Creating new asset with script
    Best Answer

    Posted Tue October 18, 2022 09:37 AM
    From which application are you trying to add the asset?
    The below sample code is working when run from Asset app (hence the usage of getThisMboSet()) and creates new asset.
    It should work similarly from a different application.
    In my case location and classification were mandatory fields.

    aktSet = mbo.getThisMboSet()
    jAkt = aktSet.add()
    jAkt.generateAutoKey()
    jAkt.setValue("DESCRIPTION","Test create new asset")
    jAkt.setValue("LOCATION","xxx")
    jAkt.setValue("CLASSSTRUCTUREID","xxx")
    aktSet.save()
    aktSet.clear()
    aktSet.close()

    ------------------------------
    Dragos Chitu
    ------------------------------



  • 19.  RE: Creating new asset with script

    Posted Wed October 19, 2022 12:14 AM
    Yes, I'm using ASSET application. 
    And this really works. Thank You! 
    I was using some example, which I had, which was not working from the same application, and it seems, that I somehow incorrectly made that aktSet for this case.

    There is just one side effect - after running script, that asset form is cleared in interface. For user it could be confusing.
    Thought about skipping one of these 
    aktSet.clear()
    aktSet.close()
    Removing both, "helps". It stays on asset.
    As I remeber, that would keep something in memory somewhere, which could fill it in some time. Or that was, when mxServer "option" is used?


    ------------------------------
    Juris Flugins
    ------------------------------



  • 20.  RE: Creating new asset with script

    Posted Wed October 19, 2022 03:20 AM
    See section "Closing the MboSet" in the document below.
    https://www.ibm.com/support/pages/system/files/inline-files/Scripting_Best_Practices_For_Performance.pdf

    No need to explicitly call clear and close for the current mboset or mboset created through a relationship.
    However, clear and close must be called for mboset created using MXServer.getMXServer().getMboSet(...)

    ------------------------------
    Dragos Chitu
    ------------------------------