VMware Cloud Community
Dlally1
Contributor
Contributor

How to dynamically setup input array values

So I can create actions to dynamically set input variables based on other inputs.  However i'm unable to set defaults of an array, like I don't even see the array properties to even extract.  I have a disks array for all the disks I'm trying to look at.  I'd like to set defaults based on the OS, like windows vs linux.

0 Kudos
1 Reply
Dlally1
Contributor
Contributor

So I've been able to extract my disks array input successfully now.  The hard part now, how can I update this custom disks input array to add multiple key/values?  For example, size 1, label "test drive", mountpoint D.   Basically we're wanting to put in a D drive if the user forgets to add one, as this D drive is critical to our base builds. 

 

Using the code below that I've pulled from another blog, this works fine for updating properties or adding properties.  However I'm not sure how to utilize this to add to an array.  

 

For example, if I see this:

var diskarray = '[{"size":1,"drivelabel":"Test Drive","mountpoint":"F"}]'

 

I'd want to add a new drive, to end up like this:

[{"size":1,"drivelabel":"Test Drive","mountpoint":"F"},{"size":5,"drivelabel":"Data Drive","mountpoint":"D"}]

 

 

 

function dumpProperties(props,lvl){
         var keys = props.keys;
         var prefix = ""
     for (var i=0; i<lvl; i++){
                   prefix = prefix + "";
          }
          for (k in keys){
                 var key = keys[k];
                 var value = props.get(keys[k])
                 if ("Properties" == System.getObjectType(value)){
                  System.log(prefix + key + "[")
                  dumpProperties(value,(lvl+2));
                  System.log(prefix+ "]")
                 } else{
                   System.log( prefix + key + ":" + value)
                 }
                 }
   }
   dumpProperties(inputProperties, 0)
   customProps = inputProperties.get("customProperties")
   dumpProperties(customProps, 0)





customProperties = new Properties();
//This will update the current projectCode property to show
//that a property can be overwritten by a workflow
customProperties.put("Test", "Testing vRO")
//This will add a new property that did not yet exist in the request
customProperties.put("NewfromvRO", "Test123")
//other properties are not updated and therefor not affected

 

 

0 Kudos