<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Automation Scripting: parameter values overridden when calling an operation from another operation in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/automation-scripting-parameter-values-overridden-when-calling-an/m-p/318464#M5465</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two scripted operations (Automation Scripting) like these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;scriptedOperation id="Operation.One"&amp;gt;
    &amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
    &amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
    &amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
    &amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
    &amp;lt;script&amp;gt;
        &amp;lt;![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
                
                    ]]&amp;gt;
    &amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;

&amp;lt;scriptedOperation id="Operation.Two"&amp;gt;
    &amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
    &amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
    &amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
    &amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
    &amp;lt;script&amp;gt;
        &amp;lt;![CDATA[
        function run(input, params) {

            try {

                Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks });

                if(!params.skipInitialChecks) {
                    // Do initial checks
                }
                
                // Do other things
                
                    ]]&amp;gt;
    &amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;In the example code, I call to &lt;STRONG&gt;Operation.One&lt;/STRONG&gt; with parameter skipInitialChecks set to &lt;STRONG&gt;false&lt;/STRONG&gt; (initial checks will be performed in Operation.One). But then from this operation I call to &lt;STRONG&gt;Operation.Two&lt;/STRONG&gt; with skipInitialChecks set to &lt;STRONG&gt;true&lt;/STRONG&gt; (so initial checks won't be performed in Operation.Two).&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;If I modify my code to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;scriptedOperation id="Operation.One"&amp;gt;
&amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
&amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
&amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
&amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
&amp;lt;script&amp;gt;
&amp;lt;![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
]]&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&amp;lt;scriptedOperation id="Operation.Two"&amp;gt;
&amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
&amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
&amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
&amp;lt;param name="skipInitialChecks2" type="boolean" /&amp;gt;
&amp;lt;script&amp;gt;
&amp;lt;![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks2 });
if(!params.skipInitialChecks2) {
// Do initial checks
}
// Do other things
]]&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then it works as expected. The problem is that this code is simplified, and sometimes I cannot / do not want to change parameter names.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;I think that the parameter values are overriden in class AutomationScriptingParamsInjector.&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;Please let me know if you need more information.&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance,&lt;/P&gt;
&lt;P&gt;Ibai.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 15:01:33 GMT</pubDate>
    <dc:creator>ioihanguren_</dc:creator>
    <dc:date>2022-04-26T15:01:33Z</dc:date>
    <item>
      <title>Automation Scripting: parameter values overridden when calling an operation from another operation</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/automation-scripting-parameter-values-overridden-when-calling-an/m-p/318464#M5465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two scripted operations (Automation Scripting) like these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;scriptedOperation id="Operation.One"&amp;gt;
    &amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
    &amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
    &amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
    &amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
    &amp;lt;script&amp;gt;
        &amp;lt;![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
                
                    ]]&amp;gt;
    &amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;

&amp;lt;scriptedOperation id="Operation.Two"&amp;gt;
    &amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
    &amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
    &amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
    &amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
    &amp;lt;script&amp;gt;
        &amp;lt;![CDATA[
        function run(input, params) {

            try {

                Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks });

                if(!params.skipInitialChecks) {
                    // Do initial checks
                }
                
                // Do other things
                
                    ]]&amp;gt;
    &amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;In the example code, I call to &lt;STRONG&gt;Operation.One&lt;/STRONG&gt; with parameter skipInitialChecks set to &lt;STRONG&gt;false&lt;/STRONG&gt; (initial checks will be performed in Operation.One). But then from this operation I call to &lt;STRONG&gt;Operation.Two&lt;/STRONG&gt; with skipInitialChecks set to &lt;STRONG&gt;true&lt;/STRONG&gt; (so initial checks won't be performed in Operation.Two).&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;If I modify my code to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;scriptedOperation id="Operation.One"&amp;gt;
&amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
&amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
&amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
&amp;lt;param name="skipInitialChecks" type="boolean" /&amp;gt;
&amp;lt;script&amp;gt;
&amp;lt;![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
]]&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&amp;lt;scriptedOperation id="Operation.Two"&amp;gt;
&amp;lt;category&amp;gt;javascript&amp;lt;/category&amp;gt;
&amp;lt;inputType&amp;gt;void&amp;lt;/inputType&amp;gt;
&amp;lt;outputType&amp;gt;void&amp;lt;/outputType&amp;gt;
&amp;lt;param name="skipInitialChecks2" type="boolean" /&amp;gt;
&amp;lt;script&amp;gt;
&amp;lt;![CDATA[
function run(input, params) {
try {
Log(null, { 'level': 'error', 'message': 'SKIP 2: ' + params.skipInitialChecks2 });
if(!params.skipInitialChecks2) {
// Do initial checks
}
// Do other things
]]&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;/scriptedOperation&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then it works as expected. The problem is that this code is simplified, and sometimes I cannot / do not want to change parameter names.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;I think that the parameter values are overriden in class AutomationScriptingParamsInjector.&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;Please let me know if you need more information.&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance,&lt;/P&gt;
&lt;P&gt;Ibai.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:01:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/automation-scripting-parameter-values-overridden-when-calling-an/m-p/318464#M5465</guid>
      <dc:creator>ioihanguren_</dc:creator>
      <dc:date>2022-04-26T15:01:33Z</dc:date>
    </item>
  </channel>
</rss>

