Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

Create a directory tree: How to call a global function from within a for loop

$
0
0

Hello,

I am trying to create a workflow that will create a directory tree in vCenter.

 

Concept:

Basically I am trying to run nested for loops for each tier of the tree calling a global tree.

 

Problem:

The 1st for loop works and creates the folder "Dev".  The second for loop does not work with an error message:

[2013-06-27 19:16:16.219] [I] Building folder Dev
[2013-06-27 19:16:16.474] [I] Built directory: Dev
[2013-06-27 19:16:16.476] [I] Building folder Servers
[2013-06-27 19:16:16.480] [I] TypeError: Cannot find function createFolder in object Dev. (Workflow:TEST_TNG_New_Site_Folder_Structure / Scriptable task (item2)#36)

 

I think it has to do with JavaScript not being able to call a global function into a nested object (I am not a programmer and do not know JavaScript so don't shoot me on this:( )

 

Code: (will clean this up once I get it working)

var folderBase = ["Dev","DMZ","Prod","UAT"];

var folderT1 = ["Servers","Workstations"];

var folderT2 = ["Windows","Linux"];

var folderT3 = ["Repo1","Repo2","Repo3","Repo4"];

var folderT4 = ["T1","T2","T3"];

 

// Create the folderBase level of folders

for (var i=0,l=folderBase.length; i<l; i++) {

    var rootFolder = parentFolder;

    buildFolderTree(folderBase[i]);

        // Create the folderT1 level of folders

        for (var j=0, l=folderT1.length; j<l; j++) {

            var rootFolder = folderBase[i];

            buildFolderTree(folderT1[j]);

                // Create the folderT2 level of folders

                for (var k=0, l=folderT2.length; k<l; k++) {

                    var rootFolder = folderT1[j];

                    buildFolderTree(folderT2[k]);

                        // Create the folderT3 level of folders

                        for (var x=0, l=folderT3.length; x<l; x++) {

                            var rootFolder = folderT2[k];

                            buildFolderTree(folderT3[x]);

                                // Create the folderT4 level of folders

                                for (var y=0, l=folderT4.length; y<l; y++) {

                                    var rootFolder = folderT3[x];

                                    buildFolderTree(folderT4[y]);

                                    }

                            }

                    }       

            }

    }

 

function buildFolderTree(folderName) {

        System.log("Building folder " + folderName);

        rootFolder.createFolder(folderName);

        System.log("Built directory: " + folderName);

    }

 

Any help will be appreciated.

Thanks

B


Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>