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

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

    Re: Automation Scripting: hooks into execution context

    ‏2011-05-16T16:11:28Z  
    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
    287 Posts

    Re: Automation Scripting: hooks into execution context

    ‏2011-09-19T17:49:07Z  
    • Bowser
    • ‏2011-05-16T16:11:28Z
    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

    <pre class="jive-pre"> from psdi.server import MXServer maximo = MXServer.getMXServer() changeDate = maximo.getDate() changeBy = currentUser </pre>
    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.
  • Raslan
    Raslan
    1 Post

    Re: Automation Scripting: hooks into execution context

    ‏2012-02-16T09:29:58Z  
    try this

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

    Re: Automation Scripting: hooks into execution context

    ‏2012-02-16T17:48:03Z  
    • Raslan
    • ‏2012-02-16T09:29:58Z
    try this

    user = scriptHome.getUserInfo();
    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

    Re: Automation Scripting: hooks into execution context

    ‏2012-04-03T22:30:44Z  
    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
  • mahato01
    mahato01
    5 Posts

    Re: Automation Scripting: hooks into execution context

    ‏2012-10-24T16:00:37Z  
    • Bowser
    • ‏2011-05-16T16:11:28Z
    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

    <pre class="jive-pre"> from psdi.server import MXServer maximo = MXServer.getMXServer() changeDate = maximo.getDate() changeBy = currentUser </pre>
    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.
  • agrippa
    agrippa
    25 Posts

    Re: Automation Scripting: hooks into execution context

    ‏2012-11-06T21:49:34Z  
    • SASHULL
    • ‏2011-09-19T17:49:07Z
    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.
    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

    Re: Automation Scripting: hooks into execution context

    ‏2012-12-12T13:29:56Z  
    • agrippa
    • ‏2012-11-06T21:49:34Z
    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
    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

    Re: Automation Scripting: hooks into execution context

    ‏2012-12-12T15:35:59Z  
    • sohini
    • ‏2012-12-12T13:29:56Z
    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
    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

    Re: Automation Scripting: hooks into execution context

    ‏2012-12-13T11:37:40Z  
    • agrippa
    • ‏2012-12-12T15:35:59Z
    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
    Hi,

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

    Regards,
    Sujitha
  • PSMX_Sushmita_Chattopadhyay
    1 Post

    Re: Automation Scripting: hooks into execution context

    ‏2013-09-05T03:46:59Z  
    • jcwilson
    • ‏2012-04-03T22:30:44Z
    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:

    <pre class="jive-pre"> setValue( "preparedby", getUserName()); </pre>

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

    <pre class="jive-pre"> setValue( "preparedby", getUserInfo().getPersonId()); </pre>

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

    <pre class="jive-pre"> mbo.setValue( "preparedby",mbo.getUserInfo().getPersonId()) </pre>

    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

    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