VMware Cloud Community
BrettK1
Enthusiast
Enthusiast
Jump to solution

vRA 8.x External Source Input Questions - Default Value and Conditionaly Optional

I've been searching for a bit, but either I don't know how to word my searches, or they're just not 'things', likely the former.

1) I have a VM template with an input dropdown that was populated by a vRO action.  Can one of the values (even 'first') somehow be designated as the default value?  I see in the Input editor that a vRO action (with return type 'string' it appears?) can be used to set it, but given the type the drop-down is populated with is Properties, this doesn't seem like a good option.  Writing another action that would rely on the ouput of the dropdown populating action also seems a bit wonky.

2) I would like to make this dropdown mandatory or unused based on another checkbox input.  i.e. If the checkbox is checked, I won't be using the input from the dropdown for anything, and if the checkbox is unchecked, it's mandatory.  Not that this is quite relevant, but I even set the dropdown default to '' to test optionality, and while it showed without the asterisk marking it mandatory, when I didn't select a value it gave an error...

Any conceptual help on the best way to accomplish either of these is appreciated!

0 Kudos
1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

These OU's probably won't change too much between two action calls.

You can create a wrapper action so you don't have to copy the dropdown action. For the post above you could use this:

var users = System.getModule("com.vra.dropdown").getUsersUnsorted();
return users.keys[0] || "";
 
If you have inputs (project), you can pass that to the dropdown action as well (you just need to make it as an input of the wrapper action).
 

View solution in original post

0 Kudos
6 Replies
xian_
Expert
Expert
Jump to solution

1. just put the key of the dropdown element as string into the default value. For example if you have an item defined with dropdownProperties.put("dev", "Development"), you need to use "dev" as default value to make it selected by default. There is no "first" option, if your list can be different from time to time, you need to create another action to return the first element key to make it default. If you want to make your dropdown ordered, check out https://kuklis.github.io/cma/post/custom-form-dropdown-external-source/

2. I believe you have to define a default value to make this work. Be careful, if your dropdown is not a static list, you have to make sure your default value is on the list: either with another action computing a default value, or with a fixed value always included in the dropdown.
I chose the latter, including a dummy value in the dropdown (i.e. dropdownProperties.put("none", "Not selected")) and make "none" the default. This way "Not selected" item is the default and this makes the form working.

0 Kudos
BrettK1
Enthusiast
Enthusiast
Jump to solution

Thanks for the input!

"if your list can be different from time to time, you need to create another action to return the first element key to make it default"

That's what I was afraid of - where would one create this action?  The action we're basing it off of is an 'external source' for a template input.  While you can specify an action to populate the 'default' portion, is there any way to guarantee this would run AFTER action that populates it was run, or is there some other logical place for this action to be run?

"There is no "first" option"

I don't mean anything 'ordered', just the fact that when the dropdown is displayed, there is a 'first' option, even if I don't know what it might end up being given the unordered list, but if the next part has a decent solution, having the 'none' default is a workaround.

As for the 'none', 'not selected', I had almost gone that route already, but wasn't sure how to  guarantee that 'none' during the times it WAS mandatory.  Where can error checking be put in at blueprint level (or even possibly at Custom Form level if that's necessary) to make sure 'none' isn't selected during those times it's a mandatory input (the input is used on the VM template itself for activedirectory.relativeDN, so passing it 'none' would cause the deployment to fail).

0 Kudos
xian_
Expert
Expert
Jump to solution

I have not encountered any issues with running an action to fill out the default value - I think it will run after the action providing the dropdown options (only this makes sense).

What do you mean by "external source"? Is this something you have no control of? Can't you make a call that action from another action returning the first element only? The only issue I can think of is some "nondeterministic" list that changes from invocation to invocation. In this case computing the first option would be a problem, indeed.

If your list is not ordered, there is no guarantee to find the first element though, with any method. I'm not aware of any method "peek" on the list and get/select the first item on the form itself.

Wrt. validation you can add external inputs or property groups to your blueprint (not the CF) and those will validate the possible values entered (your form cannot be submitted if inserted value is not on the list). See https://kuklis.github.io/cma/post/vra8-external-inputs-and-input-property-groups/
You have to omit the dummy entry in that action, though, to prevent it being accepted.

HTH

0 Kudos
BrettK1
Enthusiast
Enthusiast
Jump to solution

For the "external source" I'm writing this for a set of OUs that are in development / flux, and if possible would like to use it for possible other Projects that would use a different base DN (even different child domains), so I feed the vRO action with a base DN and it retrieves all the child OUs from there.  So, while I could hard-code a 'default' that likely won't change for its current usage, I'd prefer to make it as robust for future-proofing as possible.

Thanks for that link, that is one I used extensively when I was first trying to populate the dropdown.

I think what I need to figure out then is - how do I take the 'external source populated drop down list' as input to another vRO action to set a default, even if that default is arbitrary (i.e. look at the properties, and just arbitrarily return a string of the key of one of the properties).  I suppose an UGLY way to do it would be to just completely copy the current dropdown generating action, but instead of returning the properties, just return one string?  This seems very clunky (and any time one action was modified, we'd have to remember to modify the second as well?)

"You have to omit the dummy entry in that action, though, to prevent it being accepted." Exactly, thus the 'how do I accomplish the above, because otherwise it's a catch-22. "You can't have a default value without a dummy value, but you can't prevent users submitting a dummy value unless you don't have a default value".

 

Thanks again, this is ALL pretty new still (all being vRA 8, vRO, ABX, Javascript).  We've run vRA 7 for years, but since our use cases are quite small, haven't previously delved into most of what it can actually do.

0 Kudos
xian_
Expert
Expert
Jump to solution

These OU's probably won't change too much between two action calls.

You can create a wrapper action so you don't have to copy the dropdown action. For the post above you could use this:

var users = System.getModule("com.vra.dropdown").getUsersUnsorted();
return users.keys[0] || "";
 
If you have inputs (project), you can pass that to the dropdown action as well (you just need to make it as an input of the wrapper action).
 
0 Kudos
BrettK1
Enthusiast
Enthusiast
Jump to solution

Yea, it's a 1 in a million chance the OUs would change between runs, I'll take that, especially since the worst case is the request form would need to be refreshed.  Using conditionals on the Custom Form to hide/show the OU dropdown box to hide it when not relevant while having an externally generated default relieves the need for any "no selection" dummy value altogether, so awesome!

0 Kudos