VMware Cloud Community
jrichsstk
Contributor
Contributor

Create instance of dynamic type

I am trying to use the Search  box within VRA and it wants to map to an Entity type. From what i can tell the best way to do that is via the dynamic types. 

I'ved used the workflows to setup the dynamic type and had it create the workflows to query, which are obviously blank.

The output object is listed as Array/DynamicTypes:myNS.name

Since really all i need to pass over is an array of strings i didnt screw with any custom properties (not sure if they are manditory or not?)

I attempted to do something simple like this

resultsObjs = ['a','b']

which if i run that and check the return, the array size is correct but the values are nil which im guessing is it handing its inability to cast that correctly.

I've looked at all the SDK docs i could find and very few mention much about dynamic types and all of the blog posts i've found so far pretty old and based on the community (beta) dynamic type package which has apparently changed since release since none of those directions really line up right.

Any assistance would be greatlly appreciated

0 Kudos
4 Replies
iiliev
VMware Employee
VMware Employee

Indeed, simple strings like 'a' and 'b' cannot be cast to instances of dynamic type.

So, in your sample, instead of

resultObjs = ['a', 'b'];

you can use something like:

resultObjs = [DynamicTypesManager.makeObject("myNS","myDT","idA","A",null), DynamicTypesManager.makeObject("myNS","myDT","idB","B",null)];

where:

myNS - your dynamic type's namespace

myDT - your dynamic type's name

idA and idB - a couple of identifiers of instances of your dynamic type

A and B - names of the instances with the IDs listed above

IDs and names of your DT instances are arbitrary strings; but usually a dynamic type is modeled after some real type in a 3rd party system that your DT query workflow will connect to and wrap the returned result into a dynamic type instances, and in this case you can use the ID and the name of the real object as ID and name of your DT instance.

0 Kudos
jrich523
Contributor
Contributor

Awesome, thanks!

So i tried that and got an error about a null, so i changed it like so:

     DynamicTypesManager.makeObject("myNS","myDT","idA","A",[])

which now runs successfully but it says the resultObjs is not set, which seems really odd since clearly it is.

I also just tried removing the last param all together, and that also runs successfully but with "Not set" as the output for resultObjs

I attempted to debug it, but at best it just "breaks" at the workflow step, which is a script but doesnt allow me to debug the script itself, is there a way to do that?

appreciate the help!

0 Kudos
iiliev
VMware Employee
VMware Employee

Where do you see these "Not set" messages? In the "variables" tab for the workflow execution?

Are you by chance executing these query workflows directly? You should not, as they are not meant to be executed this way. Instead, the query workflows will be executed automatically by vRO when necessary. For example, findAll query workflow will be automatically executed when you run another workflow that has input parameter of your dynamic type, and you open the object chooser to select the input parameter value. findById query workflow will be executed eg. when you have another workflow that has output parameter of your dynamic type, you assign some value to this output parameter, and then open "variables" tab for the workflow execution to examine the set output value.

Also, you can use some scripting code in your custom non-query workflows to "find" your dynamic type instances, using code something like

var myObj = DynamicTypesManager.getObject("myNS", "myDT", "idA");

Note here in non-query workflow you'll be using getObject() instead of makeObject() used in query workflows, and also there are just 3 parameters. This code will automatically call your DT findById query workflow.

0 Kudos
jrich523
Contributor
Contributor

I was running them manually to validate the output, and yes it was the variables tab.

I understand that the actual inventory wont be updated because the output object (the custom dynamic objects) isnt given back to the inventory system. I did however at least expect to see that the variable was populated correctly.

It is my understanding (which is weak because the API docs dont cover any of this stuff) that in VRA the "Search text" basically queries the VRO Inventory for a certain type (the only property for the Search box that isnt a name/display related property)

Because this is a search box (only needs an array of strings) i had assumed that it would just look at the "name" property of those custom objects to determine the value to display in the search box. However this is just an assumption since i am unable to find any useful references to the search box.

So after figuring that out i started to dig in to the dynamic types because this looked to be the only way to create a new entity type, which i HOPE is correct (again cant find any docs that reference this so its all best guess for me)

I have been able to find some examples of how to use a dropdown list, which is oddly way different from what i can tell. In this case because i'll likely have 100-200 options so a dropdown list just isnt ideal. I've tried searching for examples/tutorials/docs on the "search box" or "search text" or even simply scanning all the API docs for "Search" with the only related item being the table of form controls, stating that a search box is an option that works like auto complete.

So the real goal here is to utilize the Search field on a xaas blueprint so that i can query a system for available options. Most of the blogs i have found that have any relation to this at all are using the older Community dynamic Types package that apparently had some CRUD workflow items that they used to slap a REST URL in. I cant find those workflows to even see what they would make but in this case i will have to query puppet for a list of roles and then filter those roles based on naming rules we have.

Again i really appreciate your assistance with this, the docs are so horrible Smiley Sad

0 Kudos