How to call an automation script from an automation script in Maximo - maximo

Could anyone tell me how to invoke an action automation script from an automation script in Maximo. I have achieved this before but can't remember/find the procedure used to call an action script.

When invoking another script, it doesn't matter if it is an action script or a script just sitting out there with no launch points (or even one already triggering on its own otherwise with, say, an object save launch point). The below code assumes Jython and Maximo of at least 7.6.0.x (I forget exactly what version added this feature).
First, you do need to make sure you import java.util.HashMap into your script. Then, you start by creating a new HashMap. This is the script context that you will put all of your implicit variables into for the other script. You then use the "invokeScript" method of the implicit service or script context (if this is in an integration script) object. The first parameter of that method is the name of the new script you want to invoke and the second parameter is your HashMap that is the context for the new script.
from java.util import HashMap
subScriptCtx = HashMap()
subScriptCtx.put("mbo", woMbo)
subScriptCtx.put("var1", someObject)
subScriptCtx.put("var2", MXServer.getMXServer().getDate())
...
service.invokeScript("OTHERSCRIPTNAME", subScriptCtx)

Related

How to access Groovy script from SAP CPI Script Collection in another Script?

I try to access a groovy script from a script collection in another script (SAP CPI). The script from the script collection contains an enumeration and i want to access this enumeration in a message mapping script. So i do the following:
Create the script in the script collection (same package as the iFlow)
Reference the script in the integration flow
Import the enumeration and use it (it's a script function used in message mapping)
Simulate the mapping (which works if i copy enum to mapping script as well)
Runtime exception during processing target field mapping /ns1:Messages/ns1:Message1/PerPhone/PerPhone/phoneType. The root message is: Exception:[com.sap.aii.mappingtool.tf7.rt.BehaviorInvocationException: groovy.lang.MissingPropertyException: No such property: BonusScheme for class: Script29] in class com.sap.aii.mappingtool.tf7.ScriptHandler method addPicklistValue[[Ljava.lang.String;#1e57ab7f, [Ljava.lang.String;#29c56946, [Ljava.lang.String;#11ba6ab8, [Ljava.lang.String;#3d2f6b53, [Ljava.lang.String;#1e0033da, com.sap.aii.mappingtool.tf7.rt.ResultListImpl#1c8de605, com.sap.xi.mapping.camel.impl.MappingContextImpl#470ff907, com.sap.aii.mappingtool.tf7.rt.Context#5e20a086] on the exchange: Exchange[ID-ff2d2c8d-4286-4e5a-5b75-1556-1657430698694-1068-1]
Seems that my enumeration isn't known and therefore can't be referenced. I'm just asking myself - why? It's everything deployed. Someone has an idea?
I think You cannot reference a Script from Script Collection in a Messaging Mapping.
Even if you want to reuse a Common Script like getHeaders or getProperties Script as Custom Function from a Script Collection, You cannot.
it's just the way it was built.

Executing a python script in snaplogic

I am trying to run a python script through script snap in snaplogic. I am facing some issues where it ask me to declare a script hook variable. Can you please help me on that.
With the script snap you should use the "Edit Script" button on the snap itself. This will open a script editor and generate a skeleton script in the language you've selected (Py in this case).
In the skeleton you can see the baseline methods and functions we define. In there you can see the usage and comments of the scripthook var. If you have an existing script I would recommend trying to write it into this skeleton's execute method than trying to implement scripthook in your existing code. You can also define your own methods and functions within the confines of the skeleton class and reference them with "this." notation.
For faster answers on SnapLogic related questions I'd recommend visiting the SnapLogic Community site.
As explained by #dwhite0101, within Script Snap when you click Edit Script you get an option to generate code template.
ScriptHook is an interface that is implemented as callback mechanism for Script Snap to call into the script.
It helps you to deal with input and output rows. The constructor below initializes the input, output, error and log variables.
self object is similar to this in c++ that holds the current row values.
class TransformScript(ScriptHook):
def __init__(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
You can perform transformations in execute method:
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
in_doc = self.input.next()
wrapper = java.util.HashMap()
for field in in_doc:
#your code
Next step is to store your results in an object and output it:
wrapper['original'] = result
self.output.write(result, wrapper)
Make sure to indent your code properly.

confusion in context variable and Context Class in soap Ui

context,testRunner variables(built-in) in SoapUI are objects/instances of which classes in soapui api.
I was under impression that context variable is an instance of
com.eviware.soapui.impl.wadl.inference.schema.Context
but in the Context class i could not find exapnd method which we use regualrly as shown below
context.expand('${#level#request}')
Please some body clarify...if both are difference where can i find list of all methods of context variable
Thanks
The class of the context variable could be different depending on context.
The best way to get the class name to print it out:
log.info( context.getClass() )
If we talk about groovy script test step then context should be
com.eviware.soapui.impl.wsdl.panels.support.MockTestRunContext if you run just your script without running the whole test case.
com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext if you run the whole or part of the test case including your script.
probably it could be other for different soapui project types..
So, what is the context of your groovy script?
Btw, how did you get com.eviware.soapui.impl.wadl.inference.schema.Context ?
SoapUI initializes certain variables in certain level.
Here are the list of variables available at different level.
Project Setup Script
context
project
runner
log
Similarly, below variables available at Test Suite Setup Script
context
testSuite
runner
log
And also certain variables available in Test Case Setup Script.
The same is with TearDown Scripts as well.
However, If I understand right, you were referring to Groovy Script test step.
And the following variables are available there are:
testRunner
context
log
To be more precise, context.expand() is used to read certain property values either from test case, suite or project.
In order to read test case level property, CASE_PROPERTY
User one of the two:
context.expand('${#TestCase#CASE_PROPERTY}')
context.testCase.getPropertyValue('CASE_PROPERTY')
In order to read test suite level property, SUITE_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')
In order to read test project level property, PROJECT_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')

Is it possible to incorporate an environment variable into a ruby script for Calabash?

I am testing a feature on an app that requires the user to be a certain age. The only time you see the prompt that asks for your age is once you open the app for the first time and once you log out of the app. I don't want my test to only go through my steps to log in and then log out to be able to see this prompt, but I also don't want to manually reset the data in between tests either. Isn't this why we write scripts? Anyways, before I launch the test, I use the environment variable RESET_BETWEEN_SCENARIOS=1 cucumber features/my_feature.feature. Is there a way that I can use this variable INSIDE of my step definition so that it resets the data on its own once I run the script?
I'm not familiar with Calabash, but it appears to be using cucumber. If that is the case, you could handle the action in a before or after hook which would run before or after each scenario.
Within the features/support folder, add a file hooks.rb
Before() do
if ENV['RESET_BETWEEN_SCENARIOS'] == '1'
#code to reset data
end
end
This could also be run after the scenario by using After() do. The same if/then could be used within a scenario step as well.

disallow to call run() in a groovy script

I am using a GroovyShell to run Groovy scripts in a JVM. The GroovyShell is using several AST customizers and some predefined methods defining a DSL. But I found by hasard that it was possible to write "run()" in any groovy script, making it to run in an infinite loop.
Does anyone know how to disallow calling "run()" in a script that is already running ?
I tried to override the script's invokeMethod and set a flag to disable the run method when the script is running... but whatever I do, I can still call this run() method in the script, it seems without going trough the script's invokeMethod.
Thanks in advance for your help
Add this line to every script you execute:
this.metaClass.run { null }

Resources