04-26-2022 11:01 AM
Hi,
I have two scripted operations (Automation Scripting) like these:
<scriptedOperation id="Operation.One">
<category>javascript</category>
<inputType>void</inputType>
<outputType>void</outputType>
<param name="skipInitialChecks" type="boolean" />
<script>
<![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 1: ' + params.skipInitialChecks });
if(!params.skipInitialChecks) {
// Do initial checks
}
Operation.Two(input, {
'skipInitialChecks': true
});
// Do other things
]]>
</script>
</scriptedOperation>
<scriptedOperation id="Operation.Two">
<category>javascript</category>
<inputType>void</inputType>
<outputType>void</outputType>
<param name="skipInitialChecks" type="boolean" />
<script>
<![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks });
if(!params.skipInitialChecks) {
// Do initial checks
}
// Do other things
]]>
</script>
</scriptedOperation>
Inside each operation, I have some initial checks that should be performed if I call the operation directly, but if I call it from another operation, then the checks shouldn't be executed. I have created a parameter named "skipInitialChecks" for that.
In the example code, I call to Operation.One with parameter skipInitialChecks set to false (initial checks will be performed in Operation.One). But then from this operation I call to Operation.Two with skipInitialChecks set to true (so initial checks won't be performed in Operation.Two).
But the operation ignores my parameter value, and takes the initial value for skipInitialChecks. It seems that the parameters passed to Operation.One are stored as ChainParameters, and when I call to other operations from inside Operation.One, ChainParemeter values override any passed parameter with the same name.
If I modify my code to this:
<scriptedOperation id="Operation.One">
<category>javascript</category>
<inputType>void</inputType>
<outputType>void</outputType>
<param name="skipInitialChecks" type="boolean" />
<script>
<![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 1: ' + params.skipInitialChecks });
if(!params.skipInitialChecks) {
// Do initial checks
}
Operation.Two(input, {
'skipInitialChecks2': true
});
// Do other things
]]>
</script>
</scriptedOperation>
<scriptedOperation id="Operation.Two">
<category>javascript</category>
<inputType>void</inputType>
<outputType>void</outputType>
<param name="skipInitialChecks2" type="boolean" />
<script>
<![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks2 });
if(!params.skipInitialChecks2) {
// Do initial checks
}
// Do other things
]]>
</script>
</scriptedOperation>
Then it works as expected. The problem is that this code is simplified, and sometimes I cannot / do not want to change parameter names.
Besides, it seems strange that the param values I've set directly when I call the second operation are ignored and replaced with the ones set to call the first operation.
I think that the parameter values are overriden in class AutomationScriptingParamsInjector.
Is this the expected behavior? Am I missing some configuration or is there any way to tell the operation to prioritize the passed params instead of the values stored in ChainParameters? Am I using scripted operations for something that they aren't prepared for and should I use plain Java operations instead? Is this a bug?
Please let me know if you need more information.
Thanks a lot in advance,
Ibai.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.