VMware Cloud Community
GarTomlon
Enthusiast
Enthusiast
Jump to solution

Dynamic list of Tagging Categories

YEsterday, I had assistance in creating a dynamic list of tags within a vSphere vapi endpoint.  I would like to take that a step further.  I would like to create a dropdown list on the categories.  I have the input parameter created (string).  I also have partial action created with it assigned to the Predefined List of Elements property on the presentation.  I am getting an empty dropdown list.    I am not even sure if I am close.  It is as follows:

// Set the VAPI endpoint to the first endpoint returned

var endpoints = VAPIManager.getAllEndpoints(); 

var endpoint = endpoints[0]

//Fetch Categories

var client = endpoint.client();

var category = new com_vmware_cis_tagging_category(client);

var categories = category.list();

var outputCats = [];

for (var i in categories)

     {

          outputCats.push(category.name)

     }

System.log(outputCats);

return outputCats;

Reply
0 Kudos
1 Solution

Accepted Solutions
daphnissov
Immortal
Immortal
Jump to solution

There's already an action built for you in the module com.vmware.vapi.tags called "listTagCategories" which does this just fine.

View solution in original post

Reply
0 Kudos
5 Replies
daphnissov
Immortal
Immortal
Jump to solution

There's already an action built for you in the module com.vmware.vapi.tags called "listTagCategories" which does this just fine.

Reply
0 Kudos
GarTomlon
Enthusiast
Enthusiast
Jump to solution

And I am trying to reinvent the wheel.  Thank you very much.  Its perfect.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The for loop body is wrong, as you are not using the iteration value anywhere. To fix the code, replace the loop:

for (var i in categories)

{

    outputCats.push(category.name)

}

with

for (var i in categories)

{

    outputCats.push(category.get(categories[i]).name)

}

The category.list() call returns an array of strings which are the IDs of the found tagging categories.

In my variant of the loop the interesting parts are:

categories[i] - contains the next category ID being iterated

category.get(categories[i]) - returns the tagging category object having this ID

category.get(categories[i]).name - fetches the name property of the retrieved tagging category object

At the end, this loop will push these names in the outputCats array and you should see it in the presentation dropdown

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

daphnissov​ - do you know where does this action listTagCategories come from? I don't think it is bundled as part of the vAPI plug-in.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

You're right, apologies, I should have dug a little deeper. This action is provided as part of a package called com.vGoodie-Bag.library.vapi.package which is a fork of Oliver Leach's com.virtualdevops.tags.package package. The package itself is hosted on GitHub here.

Reply
0 Kudos