Skip to content

Instantly share code, notes, and snippets.

@standit
Last active February 22, 2021 19:10
Show Gist options
  • Save standit/5e680881681b0943835e2f830811effb to your computer and use it in GitHub Desktop.
Save standit/5e680881681b0943835e2f830811effb to your computer and use it in GitHub Desktop.
Get Attribute Value in vRO Configuration Element, new Attribute created it if it does not exist
// VMware vRealize Orchestrator action sample. Valid for vRA/vRO 7.0+
//
// Get or Create a Configuration Element
//
// Action Inputs:
// configElement ConfigurationElement Configuration Element where attribute resides
// attributeName string Name of Attribute
// defaultAttributeValue Any Object used for default value of attribute
// lockId string Lock ID. Required if values are being set dynamically using setAttributeKey
//
// Action Output:
// return type: Any
LockingSystem.lockAndWait(lockId, workflow.id);
System.debug("Obtained lock for reading Configuration: "+configElement.name+" Attribute: "+attributeName);
var attributeValue = null;
try {
configElement.reload();
//Find value of attribute in this configuration element
try {
attributeValue = configElement.getAttributeWithKey(attributeName).value;
System.debug("Value of attribute "+attributeName+": "+attributeValue);
}catch (e) {
System.warn(e);
System.debug("Attribute "+attributeName+" does not exist. Creating this attribute. Type of attribute will be same as that of the given default value");
if(defaultAttributeValue == null || defaultAttributeValue == undefined) {
throw "Unable to create the attribute. Default value is not provided";
} else {
configElement.setAttributeWithKey(attributeName, defaultAttributeValue);
attributeValue = defaultAttributeValue;
}
}
} catch(e) {
System.warn(e);
} finally {
LockingSystem.unlock(lockId, workflow.id);
System.debug("Released lock for reading Configuration: "+configElement.name+" Attribute: "+attributeName);
}
return attributeValue;
@better-think
Copy link

is it possible to delete/remove configurationElement by code or actionElement?
if there is, please share the code with me.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment