1 Reply Latest reply on Sep 4, 2019 7:53 AM by eoinbyrne

    Array of Objects

    sean_gadson Novice

      Hello,

      I am trying to create a capacity report to email out every so often from vRA with vRO but I am having trouble creating a property array of property objects.  For some reason even though it iterates through the all of the reservations (7).  In the end it only prints out the last reservation name 7 times

       

       

      resrevationProperties = new Properties {}

      reservationCapacityInformation = []

      for (var i = 0; i < reservations.length; i++) {

      var reservStorages = reservations[i].getLink(vcacHost, "HostReservationToStorages");

      reservationName = reservations[i].getProperty("HostReservationName");

      var storage = reservStorages[0].getLink(vcacHost, "HostToStorage")[0];

      var storagePath = storage.getProperty("StoragePath");

      reservationCapacityInformation.push(resrevationProperties);

      }

       

       

      for each (var prop in reservationCapacityInformation){

      System.log(prop.get("ReservationName"));

      System.log(prop.get("StoragePath"))

      }

       

       

      output:

      [2019-09-04 10:31:23.507] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.508] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.509] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.510] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.511] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.512] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.513] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.515] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.516] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.518] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.519] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.521] [I] Storage path of Last Reservation

      [2019-09-04 10:31:23.523] [I] Reservation Name of Last Reservation

      [2019-09-04 10:31:23.524] [I] Storage path of Last Reservation

        • 1. Re: Array of Objects
          eoinbyrne Hot Shot

          Try this?

           

           

           

           

           

          reservationCapacityInformation = [];

           

          for (var i = 0; i < reservations.length; i++) {

              var reservStorages = reservations[i].getLink(vcacHost, "HostReservationToStorages");

              reservationName = reservations[i].getProperty("HostReservationName");

              var storage = reservStorages[0].getLink(vcacHost, "HostToStorage")[0];

              var storagePath = storage.getProperty("StoragePath");

           

             // create a new one each time...

              var resrevationProperties = new Properties();

              reservationProperies.put("ReservationName", reservationName);

              reservationProperties.put("StoragePath", storagePath);

           

              reservationCapacityInformation.push(resrevationProperties);

          }

           

           

          for each (var prop in reservationCapacityInformation){

              System.log(prop.get("ReservationName"));

              System.log(prop.get("StoragePath"))

          }