VMware Aria Automation Orchestrator

 View Only
  • 1.  Receive array from PS Host / getRootObject()

    Posted Jul 17, 2024 03:58 PM

    Hello, 

    I am struggling understanding the getRootObject() on a received PS object. I have read the previous threads here, but they dont make it clear for me. 

    In my PS code, I return an array with a set of associate arrays. 

    Outputting the object with System.log(JSON.stringify(psData, null4)); I get:

    [ { "scope1": 11 }, { "scope2": 22 } ]

    Running:

     for each (psDataItem in psData)
        {
            System.log(psDataItem);
        }

    I get 

    HashMap:1300406423
    HashMap:1806090958
    which must be the two entries. 
    How can I access the entries, e.g. keys, values etc and pull key name and value?
    I can do with JSON, but I find it quite complex to navigate in the json object returned by getAsJson()
    So shortly said, is it possible to read the entries of the two HashMaps?
    Many thanks and regards, K



  • 2.  RE: Receive array from PS Host / getRootObject()

    Posted Jul 18, 2024 09:50 AM

    I've run into similar situations, so I'll share what I've done.
    Once I get my JSON response I do the following so that Orchestrator can properly read it as an array of strings:

    response = request.execute(); // this is getting me my array, in my case I'm using api, but I'd expect the response is similar to your psdata
    var responseJson = response.contentAsString; 
    var result = JSON.parse(responseJson)

    From this point I can treat the result variable as an array that Orchestrator can read and understand.
    Since you are dealing with two arrays, you may need to add some steps alongside these to get it to work.



  • 3.  RE: Receive array from PS Host / getRootObject()
    Best Answer

    Posted Jul 19, 2024 09:38 AM

    Hi,

    Please take a look if that can help or can be a base for what you need to get.

    var psData = [{ "scope1": 11 }, { "scope2": 22 }];
    
    for each(psDataItem in psData)
        {
            var key = Object.keys(psDataItem)[0]
            var value = psDataItem[key];
            System.log("key: " + key + ", value: " + value);
        }
    



    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://www.clouddepth.com
    ------------------------------



  • 4.  RE: Receive array from PS Host / getRootObject()

    Posted Jul 24, 2024 09:44 AM

    Perfect, many thanks! Works perfect!

    It was this simple - which I also somehow expected :))




  • 5.  RE: Receive array from PS Host / getRootObject()

    Posted Jul 21, 2024 04:16 PM

    I had a similar task recently and was able to wrap-up my findings in this blog post: https://kuklis.github.io/cma/post/vro8-powershell-result/

    HTH