Question

Need to use object from two List as different parameters inside For Each Loop

  • 21 March 2024
  • 7 replies
  • 105 views

Badge +5

Hi Team,

 

I have two different lists with names in it. I want to use each value from both the list inside for each how that can be done in workflow?

 

<App_SetClientPropertiesRequest>
    <association>
        <entity>
            <clientName>xpath:{/workflow/ForEach_1/OldName}</clientName>
            <newName>xpath:{/workflow/variables/new_name}</newName>
        </entity>
    </association>
    <clientProperties>
        <client>
            <clientEntity>
                <clientName>xpath:{/workflow/ForEach_1/OldName}</clientName>
            </clientEntity>
        </client>
    </clientProperties>
</App_SetClientPropertiesRequest>

 

xpath:{/workflow/variables/new_name} has a list of names which is not working, everytim it is taking same object it also should work as ForEach value which can be used, any idea or suggestion


7 replies

Badge +5

Hi Team,

Could someone please help me with this.

Badge +5

Hi Team,

Could you please help me with any ideas or suggestions on this. I need to replace old names with new names on bulk number of servers. I am trying to do the same by creating a workflow using the XML.

 

I want to use below XML parameter in loop

<clientName>value</clientName>
            <newName>value</newName>

I am able to use only one value in loop using for each, can both the parameter values be used in loop.

 

I am able to run it in loop using Powershell method but I need to create csv file n import all the values in there. Looking for an alternative using workflows

Userlevel 2
Badge +10

How are you inputting the data?

 

 

Badge +5

In Workflow have created two Inputs i.e.Old Name and New Name as multiline string and added the values to the variable. Using Old name variable in for each to perform action against each of the old names.

Userlevel 5
Badge +16
<?xml version="1.0" encoding="UTF-8"?>
<Workflow_WorkflowDefinition apiMode="0" config="&lt;configuration />" description="" executeOnWeb="0" inputs="&lt;inputs>&lt;newServers class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;oldServers class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;/inputs>" interactive="0" isHtmlDescription="0" manualPercentageComplete="0" name="MergeServerLists" outputs="&lt;outputs />" revision="$Revision: $" tags="" uniqueGuid="e05073e9-637f-4200-8f92-fc4a87b93f28" variables="&lt;variables>&lt;currentOldServer class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;currentNewServer class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;/variables>" webHidden="0">
<schema>
<outputs className="" name="outputs" type=""/>
<variables attribute="0" className="" name="variables" type="">
<children attribute="0" className="java.lang.String" controlType="0" defaultValue="" displayName="" hidden="0" inputType="java.lang.String" listType="0" name="currentOldServer" type="{http://www.w3.org/2001/XMLSchema}string"/>
<children attribute="0" className="java.lang.String" controlType="0" defaultValue="" hidden="0" inputType="java.lang.String" listType="0" name="currentNewServer" type="{http://www.w3.org/2001/XMLSchema}string"/>
</variables>
<inputs attribute="0" className="" name="inputs" type="">
<children attribute="0" className="java.lang.String" controlType="0" defaultValue="" hidden="0" inputType="java.lang.String" listType="0" name="newServers" type="{http://www.w3.org/2001/XMLSchema}string"/>
<children attribute="0" className="java.lang.String" controlType="0" defaultValue="" displayName="" hidden="0" inputType="java.lang.String" listType="0" name="oldServers" type="{http://www.w3.org/2001/XMLSchema}string"/>
</inputs>
<config className="" name="configuration" type=""/>
</schema>
<Start breakpoint="0" commented="0" continueOnFailure="0" created="0" description="" displayName="Start" height="36" interactive="0" jobMode="0" name="Start" originalStyle="" skipAttempt="0" style="image;image=/images/jgraphx/house.png" uniqueName="Start_1" waitSetting="0" width="58" x="161" y="0">
<inputs val="&lt;inputs />"/>
<transition activity="Script_1" commented="0" description="" originalStyle="" points="190.0,69.09375;190.0,95.09375" sourceX="70" sourceY="60" status="0" style="defaultEdge;noEdgeStyle=1;orthogonal=1" targetX="270" targetY="180" transitionIndex="0" x="0" y="0">
<condition language="4" script="/*&#xa;The expression should return a boolean. Use the variable name &quot;activity&quot; to refer to the previous activity object. Example:&#xa;activity.exitCode==0;&#xa;*/&#xa;"/>
</transition>
</Start>
<Activity breakpoint="0" commented="0" continueOnFailure="0" created="1711472120703" description="" displayName="Merge Server Lists" height="34" interactive="0" jobMode="0" name="Script" namespaceUri="commvault.cte.workflow.activities" originalStyle="" skipAttempt="1" style="label;image=commvault.cte.workflow.activities.ScriptActivity;shadow=0" uniqueName="Script_1" waitSetting="0" width="138" x="121" y="107">
<inputs val="&lt;inputs>&lt;script language=&quot;4&quot; script=&quot;//Merge Lists&amp;#xD;&amp;#xA;String oldServers = xpath:{/workflow/inputs/oldServers};&amp;#xD;&amp;#xA;String newServers = xpath:{/workflow/inputs/newServers};&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;List serverMaps = new ArrayList();&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;ArrayList oldServerList = oldServers.split(&amp;quot;[^a-zA-Z0-9-.]&amp;quot;);&amp;#xD;&amp;#xA;ArrayList newServerList = newServers.split(&amp;quot;[^a-zA-Z0-9-.]&amp;quot;);&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;// Compare list sizes&amp;#xD;&amp;#xA;int oldservercount = oldServerList.size();&amp;#xD;&amp;#xA;int newservercount = newServerList.size();&amp;#xD;&amp;#xA;int index = 0;&amp;#xD;&amp;#xA;for (oldServer : oldServerList){&amp;#xD;&amp;#xA; String newServer = newServerList.get(index);&amp;#xD;&amp;#xA; &amp;#xD;&amp;#xA; Map serverMap = new HashMap();&amp;#xD;&amp;#xA; &amp;#xD;&amp;#xA; &amp;#xD;&amp;#xA; serverMap.put(&amp;quot;oldServer&amp;quot;, oldServer);&amp;#xD;&amp;#xA; serverMap.put(&amp;quot;newServer&amp;quot;, newServer); &amp;#xD;&amp;#xA; serverMaps.add(serverMap);&amp;#xD;&amp;#xA; index++;&amp;#xD;&amp;#xA;}&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;workflow.setVariable(&amp;quot;serverMaps&amp;quot;, serverMaps);&amp;#xD;&amp;#xA;return serverMaps;&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;&quot; />&lt;/inputs>"/>
<transition activity="ForEach_1" commented="0" description="" originalStyle="" points="190.0,153.09375;190.0,179.09375" sourceX="320" sourceY="190" status="0" style="defaultEdge;noEdgeStyle=1;orthogonal=1" targetX="320" targetY="310" transitionIndex="0" x="0" y="0">
<condition language="4" script="/*&#xa;The expression should return a boolean. Use the variable name &quot;activity&quot; to refer to the previous activity object. Example:&#xa;activity.exitCode==0;&#xa;*/&#xa;"/>
</transition>
</Activity>
<Activity breakpoint="0" commented="0" continueOnFailure="0" created="1711473260586" description="" displayName="ForEach" height="240" interactive="0" jobMode="0" name="ForEach" namespaceUri="commvault.cte.workflow.activities" originalStyle="" skipAttempt="1" style="swimlane" uniqueName="ForEach_1" waitSetting="0" width="160" x="110" y="180">
<inputs val="&lt;inputs>&lt;name class=&quot;java.lang.String&quot;>output&lt;/name>&lt;values class=&quot;java.lang.Object&quot; _list_=&quot;false&quot;>xpath:{/workflow/Script_1/output}&lt;/values>&lt;numberOfParallelExecutions class=&quot;java.lang.Integer&quot; _list_=&quot;false&quot;>1&lt;/numberOfParallelExecutions>&lt;continueOnFailure class=&quot;java.lang.Boolean&quot; _list_=&quot;false&quot;>false&lt;/continueOnFailure>&lt;/inputs>"/>
<superProcess>
<Start breakpoint="0" commented="0" continueOnFailure="0" created="1711473260586" description="" displayName="Start" height="30" interactive="0" jobMode="0" name="Start" originalStyle="" skipAttempt="1" style="label;fillColor=#FFFF33;gradientColor=#FFFF00;shadow=0" uniqueName="Start_2" waitSetting="0" width="120" x="14" y="33">
<inputs val="&lt;inputs />"/>
<transition activity="scrMaps2Variables" commented="0" description="" originalStyle="" points="74.0,75.0;74.0,101.0" sourceX="80" sourceY="50" status="0" style="defaultEdge;noEdgeStyle=1;orthogonal=1" targetX="170" targetY="130" transitionIndex="0" x="0" y="0">
<condition language="4" script="/*&#xa;The expression should return a boolean. Use the variable name &quot;activity&quot; to refer to the previous activity object. Example:&#xa;activity.exitCode==0;&#xa;*/&#xa;"/>
</transition>
</Start>
<Activity breakpoint="0" commented="0" continueOnFailure="0" created="1711473304851" description="" displayName="Maps 2 Variables" height="34" interactive="0" jobMode="0" name="Script" namespaceUri="commvault.cte.workflow.activities" originalStyle="" skipAttempt="1" style="label;image=commvault.cte.workflow.activities.ScriptActivity;shadow=0" uniqueName="scrMaps2Variables" waitSetting="0" width="128" x="10" y="113">
<inputs val="&lt;inputs>&lt;script language=&quot;4&quot; script=&quot;Map serverMap = xpath:{/workflow/ForEach_1/output};&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;//Import Map Values&amp;#xD;&amp;#xA;String oldServer = serverMap.get(&amp;quot;oldServer&amp;quot;);&amp;#xD;&amp;#xA;String newServer = serverMap.get(&amp;quot;newServer&amp;quot;);&amp;#xD;&amp;#xA;&amp;#xD;&amp;#xA;//Save Map Values as variables&amp;#xD;&amp;#xA;workflow.setVariable(&amp;quot;currentOldServer&amp;quot;,oldServer);&amp;#xD;&amp;#xA;workflow.setVariable(&amp;quot;currentNewServer&amp;quot;,newServer);&quot; />&lt;/inputs>"/>
<transition activity="Execute_1" commented="0" description="" originalStyle="" points="74.0,159.0;74.0,185.0" sourceX="80" sourceY="100" status="0" style="defaultEdge;noEdgeStyle=1;orthogonal=1" targetX="190" targetY="180" transitionIndex="0" x="0" y="0">
<condition language="4" script="/*&#xa;The expression should return a boolean. Use the variable name &quot;activity&quot; to refer to the previous activity object. Example:&#xa;activity.exitCode==0;&#xa;*/&#xa;"/>
</transition>
</Activity>
<Activity breakpoint="0" commented="0" continueOnFailure="0" created="1711473429006" description="" displayName="Execute" height="34" interactive="0" jobMode="0" name="Execute" namespaceUri="commvault.cte.workflow.activities.cmd.operation" originalStyle="" skipAttempt="1" style="label;image=commvault.cte.workflow.activities.cmd.operation.OperationExecute;shadow=0" uniqueName="Execute_1" waitSetting="0" width="100" x="23" y="197">
<inputs val="&lt;inputs>&lt;inputXml class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;escapeXml class=&quot;java.lang.Boolean&quot; _list_=&quot;false&quot;>false&lt;/escapeXml>&lt;commandArgs class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;sessionOptions class=&quot;workflow.types.cmd.SessionOptions&quot; _list_=&quot;false&quot;>&lt;useImpersonatedAccount class=&quot;java.lang.Boolean&quot; _list_=&quot;false&quot;>true&lt;/useImpersonatedAccount>&lt;tokenFile class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;token class=&quot;java.lang.String&quot; _list_=&quot;false&quot; />&lt;/sessionOptions>&lt;/inputs>"/>
</Activity>
</superProcess>
<activitySchema>
<outputs name="outputs">
<children attribute="0" className="java.lang.Object" defaultValue="" hidden="0" inputType="java.lang.Object" listType="0" name="output" type="{http://www.w3.org/2001/XMLSchema}anyType"/>
</outputs>
<inputs className="" defaultValue="" listType="0" name="" type="">
<children attribute="0" className="java.lang.String" defaultValue="" hidden="0" inputType="java.lang.String" listType="0" name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
<children attribute="0" className="java.lang.Object" defaultValue="" hidden="0" inputType="java.lang.Object" listType="0" name="values" type="{http://www.w3.org/2001/XMLSchema}anyType"/>
<children attribute="0" className="java.lang.Integer" defaultValue="1" hidden="0" inputType="java.lang.Integer" listType="0" name="numberOfParallelExecutions" type="{http://www.w3.org/2001/XMLSchema}integer"/>
<children attribute="0" className="java.lang.Boolean" defaultValue="false" hidden="0" inputType="java.lang.Boolean" listType="0" name="continueOnFailure" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
</inputs>
</activitySchema>
</Activity>
<formProperties/>
<minCommCellVersion releaseID="16" servicePack="0"/>
</Workflow_WorkflowDefinition>

Import that workflow. 

 

Userlevel 5
Badge +16

Here is the exported xml.

Userlevel 5
Badge +16

Be warned: this doesn’t check the validity of the lists so make sure they are correct.

Reply