Topic
11 replies Latest Post - ‏2013-09-05T03:46:59Z by PSMX_Sushmita_Chattopadhyay
Bowser
Bowser
81 Posts
ACCEPTED ANSWER

Pinned topic Automation Scripting: hooks into execution context

‏2011-05-13T18:21:23Z |
Hi,

I'm trying to write an Automation Script to update custom CHANGEBY and CHANGEDATE attributes on the METER object. (The code is below.) I have managed to figure out how to get a reference to the Maximo server and obtain the current date, but I'm having trouble finding out who the current user is.

I have found documentation and code samples for TSRM or TAMIT 7.2 which talks about a "scriptHome" variable which is a reference to the current MBO. Unfortunately, it doesn't appear this "built in variable" was included with MBS 7.5, and there is no documentation on what is available to an Automation Script from its execution context.

Specific Question: How can I find out who the current user is?

General Question: What built in variables are available to me?

Thanks for your help!



Here is my Automation Script. Note that it has an Object launch point, and changeBy and changeDate are OUT direction variables bound to my CHANGEBY and CHANGEDATE attributes.


from psdi.security 

import UserInfo from psdi.server 

import MXServer   maximo = MXServer.getMXServer()   userInfo = scriptHome.getUserInfo()   changeDate = maximo.getDate() changeBy = userInfo.getUserName()
Updated on 2012-12-13T11:37:40Z at 2012-12-13T11:37:40Z by Sujita
  • Bowser
    Bowser
    81 Posts
    ACCEPTED ANSWER

    Re: Automation Scripting: hooks into execution context

    ‏2011-05-16T16:11:28Z  in response to Bowser
    Update

    I have a workaround to the specific question that may be of interest. To find out who the current user is, I've used the fact that you can use the :user bind variable in relationship where clauses to create a Relationship from METER to MAXUSER where userid = :user. I then added an IN variable called currentUser to the Automation Script and bound it to maxuser.userid in the Launch Point. After doing this, I was able to change my code to the following, and it works!

    While I have a workaround / hack that works for this situation, I would still like to know if there are any variables that Maximo supplies context through.

    Thanks!
    Bowser

    
    from psdi.server 
    
    import MXServer   maximo = MXServer.getMXServer()   changeDate = maximo.getDate() changeBy = currentUser
    
    • SASHULL
      SASHULL
      268 Posts
      ACCEPTED ANSWER

      Re: Automation Scripting: hooks into execution context

      ‏2011-09-19T17:49:07Z  in response to Bowser
      The variable for the current user is simply user. A little late I'm sure but with the little documentation that exists I hope this might help make it easier for someone else later on.
      • agrippa
        agrippa
        25 Posts
        ACCEPTED ANSWER

        Re: Automation Scripting: hooks into execution context

        ‏2012-11-06T21:49:34Z  in response to SASHULL
        A complete listing of the available implicit variables and their usage was added to the Maximo product documentation.

        Here's the link:
        http://pic.dhe.ibm.com/infocenter/tivihelp/v49r1/index.jsp?topic=%2Fcom.ibm.mbs.doc%2Fautoscript%2Fr_variables_automation_scripts.html
        • sohini
          sohini
          12 Posts
          ACCEPTED ANSWER

          Re: Automation Scripting: hooks into execution context

          ‏2012-12-12T13:29:56Z  in response to agrippa
          Hi,
          everywhere I can see the implicit variable "mbo". but when I use it in my script it gives me an error saying "NameError: name 'mbo' is not defined". Any idea ? Even the other implicit variables like, user/errorkey etc. are also not working.
          When I explicitly try to create a variable named "mbo", it gives me an error msg saying these are reserved keywords.
          Please help.

          Sohini
          • agrippa
            agrippa
            25 Posts
            ACCEPTED ANSWER

            Re: Automation Scripting: hooks into execution context

            ‏2012-12-12T15:35:59Z  in response to sohini
            Sohini,

            Which product are you testing this in? What version including Fix Pack?

            What type of launch point?

            Does a simple script where no implicit variables are used work?

            Sam
            • Sujita
              Sujita
              44 Posts
              ACCEPTED ANSWER

              Re: Automation Scripting: hooks into execution context

              ‏2012-12-13T11:37:40Z  in response to agrippa
              Hi,

              I am facing the same issue in maximo v7.5. mbo is not defined error. Any suggestion on this..

              Regards,
              Sujitha
    • mahato01
      mahato01
      5 Posts
      ACCEPTED ANSWER

      Re: Automation Scripting: hooks into execution context

      ‏2012-10-24T16:00:37Z  in response to Bowser
      woQuesAnsSet = mbo.getMboSet("G_ENVQUESANS");
      woQuesSet = mbo.getMboSet("G_ENVQUEST");
      for i in range(0,woQuesSet .count()):
      woQAS = woQuesSet .getMbo(i)
      myAns=woQuesAnsSet.addAtEnd()
      myAns.setValue("G_APP", woQAS.getString("G_APP"), 2L)
      myAns.setValue("G_CATEGORY", woQAS.getString("G_CATEGORY"), 2L)
      myAns.setValue("DESCRIPTION", woQAS.getString("DESCRIPTION"), 2L)
      This is suppose to update few lines to our workorder and works fine but this does with all the workorder. This should be updating only this mbo as the relationship specifies the wonum. I want to prevent this and update only this particular workorder. The script is set to fire on initialize and when I create a workorder from SR this does not work with only this MBO but updates all workorder. what is the alternative to scripthome in Maximo 7.5.
  • Raslan
    Raslan
    1 Post
    ACCEPTED ANSWER

    Re: Automation Scripting: hooks into execution context

    ‏2012-02-16T09:29:58Z  in response to Bowser
    try this

    user = scriptHome.getUserInfo();
    • Bowser
      Bowser
      81 Posts
      ACCEPTED ANSWER

      Re: Automation Scripting: hooks into execution context

      ‏2012-02-16T17:48:03Z  in response to Raslan
      I have found that the "Scripting with Maximo" document, linked to below, is very helpful in getting started with Automation Scripting. It talks about "implicit variables", such as "mbo" and "user", and how to properly implement each of the types of launch point. It is definitely worth a read.

      "Scripting with Maximo" can be found here: https://www.ibm.com/developerworks/mydeveloperworks/groups/service/html/communityview?communityUuid=a9ba1efe-b731-4317-9724-a181d6155e3a#fullpageWidgetId=W5f281fe58c09_49c7_9fa4_e094f86b7e98&file=83c7752c-a621-4af9-bb32-d6ba7d612ab2
  • jcwilson
    jcwilson
    36 Posts
    ACCEPTED ANSWER

    Re: Automation Scripting: hooks into execution context

    ‏2012-04-03T22:30:44Z  in response to Bowser
    Well, I've been attempting several things to bypass a bug in the HS&E Add On where the Risk Assessment app uses the username to prepopulate the "PreparedBy" column. The PreparedBy column needs the PersonID and not the UserID of the logged on user. Normally not a problem when all 3 ID's (LogonID, UserID & PersonID) are the same. But we run LDAP auth with SSO so naturally, not all three of our ID's are the same. I'll take this moment to vent some frustration with IBM's lazy or stupid developers who uses:

    
    setValue(
    "preparedby", getUserName());
    


    on a column that needs the PersonID. Instead, they should use:

    
    setValue(
    "preparedby", getUserInfo().getPersonId());
    


    Anyway, using Automation Scripting I was able to bypass this bad programming with this little bit of code:

    
    mbo.setValue(
    "preparedby",mbo.getUserInfo().getPersonId())
    


    Yes, it's a one liner. The launch point is set on initialization of the object. Many failed previous attempts used the scriptHome variable which doesn't seem to work anymore in 7.5. I remembered reading that mbo referenced the exact same thing as scriptHome so I guess they quit using scriptHome and standardized on mbo.

    Hope this helps someone.

    John
    • PSMX_Sushmita_Chattopadhyay
      1 Post
      ACCEPTED ANSWER

      Re: Automation Scripting: hooks into execution context

      ‏2013-09-05T03:46:59Z  in response to jcwilson

      Did anyone get past the NameError : name 'mbo' is not defined error?

      I am facing the asme one.

      I am trying to create a launch point on SR Object of teh Type Attribute