Concatenate variables


I’m trying to combine two custominputs as part of the name: and hostname: config for VMware Catalog.

Basically the end user specifies the servername defined by an accepted regex. However if they need to append the server name with NEW (To build and swap over a system with the same name) I would like by selecting YES this be added.

I have tried

“<%= if (customOptions.vm_input_appendname == ‘NO’){customOptions.input_vm_name} else {if (customOptions.vm_input_appendname == ‘YES’){customOptions.input_vm_name}+{customOptions.vm_input_new}} %>”


“<%= if (customOptions.vm_input_appendname == ‘NO’){customOptions.input_vm_name} else {if (customOptions.vm_input_appendname == ‘YES’){customOptions.input_vm_name}+{NEW}} %>”

But I get a message asking to “choose a plan” if Yes is selected.

input_vm_name is fieldname for the servername
vm_input_appendname is either yes or no
vm_input_new is a default hidden value of NEW

After trying with various combinations when selecting YES somehow I managed to get a servername


Which clearly is not working I’m after.

Any ideas? Is what I’m after possible?


There’s a better way to do an if statement I can share in a bit. But to answer your question, it would be something like:

"<%= customOptions.input_vm_name + 'NEW' %>"

Anything between the <%=%> is groovy syntax.

So you can adjust your if statements a bit in Groovy using ternary if statements. So instead of something like:

“<%= if (customOptions.vm_input_appendname == ‘NO’){customOptions.input_vm_name} else {if (customOptions.vm_input_appendname == ‘YES’){customOptions.input_vm_name + 'NEW'} %>”

You could utillize:

"<%= (customOptions.vm_input_appendname == 'NO') ? customOptions.input_vm_name : customOptions.input_vm_name + 'NEW' %>"

It’s now working with:
"<%= (customOptions.vm_input_appendname == 'NO') ? customOptions.input_vm_name : customOptions.input_vm_name + 'NEW' %>"