bgara
bgara

Reputation: 143

wso2esb- accessing variable outside iterator mediator

Basically, inside iterator, I am setting some variable using Script (name: setValue) mediator. I am trying to access them in the Ruby script outside the iterator.

According to the documentation: How to access property mediator outside iterator which is defined inside iterator?

Different options I tried:

1) In Ruby script, I tried using

$mc.get-property('Operation','githubhosturl1');  I am getting syntax error at operation.

2) Outside Iterator I tried accessing them using Property

<property   expression="get-property('operation','githubhosturl')  name="githubhosturl1) 

getting an error at expression.

3) In Ruby script I tried:

$mc.get-property('githubhosturl1') - Empty value returning

How can I solve this issue?

My code - proxy service - I am pasting only small portion, where there is an issue. In setValue script I am able to print the value in the console log.

<Iterator>
-------
--------
-------
<script description="setValue" language="js"><![CDATA[var log = mc.getServiceLog(); 
            var tool =  mc.getProperty('toolList');

           if( tool == "github")
           {    
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('githubhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('gitassetid',vassetid.toString());
                var vbranch="qa";
                mc.setProperty('gitbranch',vbranch.toString());
           }
           if( tool == "dockercloud")
           {
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('dockerhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('dockerid',vassetid.toString());
                var creid = mc.getProperty('jsondata');
                mc.setProperty('doccredid',creid.toString());
                var vprojName = mc.getProperty('projName');
                mc.setProperty('docproj',vprojName.toString());
           }]]></script>
        <property expression="get-property('githubhosturl')" name="githubhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('gitbranch')" name="gitbranch1" scope="operation" type="STRING"/>
        <property expression="get-property('gitassetid')" name="gitassetid1" scope="operation" type="STRING"/>
        <property expression="get-property('dockerhosturl')" name="dockerhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('doccredid')" name="doccredid1" scope="operation" type="STRING"/>
        <property expression="get-property('docproj')" name="docproj1" scope="operation" type="STRING"/>
    </sequence>
</target>
</iterate>
<script description="re" language="rb"><![CDATA[require 'erb'
     require 'erb'

     @giturl = $mc.getProperty('githubhosturl1');
      @gitbranch = $mc.getProperty('gitbranch1');
      @gitcredential = $mc.getProperty('gitassetid1');

      @dockerurl = $mc.getProperty('dockerhosturl1');
      @dockerCred = $mc.getProperty('doccredid1');
      @dockerprojectname = $mc.getProperty('docproj1');

      @template = File.read('C:\WS02\workspace\index.txt.erb')
      OutTemplate = ERB.new(@template).result( binding )

      File.open('C:\WS02\workspace\Jenkin.groovy',"w") do |f|
         f.puts OutTemplate
      end]]></script>

Upvotes: 0

Views: 262

Answers (1)

bgara
bgara

Reputation: 143

By changing all the scope inside the Iteration from "default" to "Operation" and access them outside using get-property('operation', variable) and then change the scope to "Default"

Upvotes: 0

Related Questions