VMware Cloud Community
anoopvb
Enthusiast
Enthusiast
Jump to solution

function getAttributeWithKey not found for ConfigurationElement()

In an action, i've got a script that connects to a https end point and pull some data to populate into an input field.

so i'm trying to read configuration elements and get this error

Error in (Dynamic Script Module name : GetListOfGroups#1) TypeError: Cannot find function getAttributeWithKey in object function ConfigurationElement() {

   [native code, arity=0]

Here's my code in the action

System.log("starting")

var username = ConfigurationElement.getAttributeWithKey("wfconf.username").value

var password = ConfigurationElement.getAttributeWithKey("wfconf.password").value

var vendorkey = ConfigurationElement.getAttributeWithKey("wfconf.vendorkey").value

Trying to figure out where i could be going wrong here.

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

ConfigurationElement is a scripting type. You cannot invoke the method getAttributeWithKey() directly on the type; instead, you should obtain an instance of object of this type (eg. by passing it as an input parameter to your scripting action), and then invoke getAttributeWithKey() on this instance.

See for example the scripting action com.vmware.library.configurations.getObjectFromConfigurationElementWithKey() that comes out of the box with vRO.

View solution in original post

Reply
0 Kudos
6 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

ConfigurationElement is a scripting type. You cannot invoke the method getAttributeWithKey() directly on the type; instead, you should obtain an instance of object of this type (eg. by passing it as an input parameter to your scripting action), and then invoke getAttributeWithKey() on this instance.

See for example the scripting action com.vmware.library.configurations.getObjectFromConfigurationElementWithKey() that comes out of the box with vRO.

Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

Thank you.

I figured out another way. Those values were already part of my attributes for the workflow and the action was used to populate a drop down so I just used those attributes as variables to my action and that worked out just fine Smiley Happy

thank you again.

Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

This actually proved to be quite useful. thank you iiliev

Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

iiliev

How does getAttributeWithKey() work with securestrings.

i think i cannot do

var password = config.getAttributeWithKey("password").value;

where config is the parameter in the action.

am i doing something wrong?

thanks!

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

That should work.  Are you getting an error?  I believe .value will be a string though not a secure string.

Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

you're right. initially, it returned an exception with a value of null.

i can't think of what i did to fix it but it's working as expected now. Thanks again for the tip.