VMware Cloud Community
salil3
Contributor
Contributor
Jump to solution

Handling dynamic array contents as input to field in presentation layer

Hi

One of the field in presentation layer as part of 'predefined answers' property makes a call to the action script that internally returns a array containing key and value pair

{

  "name1":"instanceid1",

  "name2":"instanceid2"

}

What I want to display to the user as part of field input are the keys i.e. name1, name2 only and when the user select the key, internally I want to fetch the correspond value (which in this case instanceid1 or instanceid2) in order to talk to the endpoint i.e. rest server.

Please let me know how to do this in vRO.

Thanks in advance,

Salil

0 Kudos
1 Solution

Accepted Solutions
jacksonecac
Enthusiast
Enthusiast
Jump to solution

http://manvsvcac.com/Articles/Lab_Resources_Round03.html

is a great example of how to access ResourceElements. Hope that helps.

View solution in original post

0 Kudos
6 Replies
jacksonecac
Enthusiast
Enthusiast
Jump to solution

if the action return is the contents of the presentation then you need to change the return of the action to the values that you want to return.

Loop through the array that is returns now and push the keys to a new array and return that one;

var newAry = [];

for(var i in oldAry)

{    

     newAry.push(i.key);

}

return newAry;

0 Kudos
salil3
Contributor
Contributor
Jump to solution

Thanks for your response!!

In my case keys are what I want to display to the user and based on the key selection the correspond value i.e. instanceid is what I want to use to communicate to the REST endpoint.

The solution that you proposed, will result into display of the keys but I will loose the metadata i.e. correspond value which is needed, to talk to the server endpoint.

Thanks and Regards,

Salil

0 Kudos
jacksonecac
Enthusiast
Enthusiast
Jump to solution

You could use a resource to build the key-pair relationship. Display the keys to the user, then query the resource object using the key as a parameter.

0 Kudos
salil3
Contributor
Contributor
Jump to solution

Appreciate your reply!

>>You could use a resource to build the key-pair relationship

By using resource you mean ResourceElement type in vRO? If possible, can you please give me an example?

0 Kudos
jacksonecac
Enthusiast
Enthusiast
Jump to solution

http://manvsvcac.com/Articles/Lab_Resources_Round03.html

is a great example of how to access ResourceElements. Hope that helps.

0 Kudos
salil3
Contributor
Contributor
Jump to solution

Yes this helped. Thank you so much!!

0 Kudos