Hi all, I have a blueprint with a vm that passes * properties and I successfullty get my custom properties in the payload. I found on the internet a script that has a function that will iterate, using recursion, through the payload and get the key/value pairs. I am trying to figure out a good way to set an attribute 'attPropertyArray', which is of type proerties, to the custom properties I have. All the custom properties (3) start with prd and are type string.
Below is the script. It DOES work if I use regex to look for, in the funciton, each custom property name by name, set an attribute to that value (string), then at the end put each of those attribute values into my properties attribute attPropertyArray. So it SEEMS that those attributes are accessible inside the function as it recurses.
The DOES NOT WORK part, where I am trying to populate the attribute of type properties inside the function as it recurses gives an error:
item: 'setPropReservationPolicyID/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot call method "put" of null (Workflow:setPropReservationPolicyID / Props from Payload (item1)#25)'
workflow: 'setPropReservationPolicyID' (5223234e-0af0-470c-8ea6-dd490265596b)
So, am I missing something obvious?
I have verified that the 'does not work' part DOES match and has the correct key/value
[2018-06-08 08:01:11.102] [I] REGEX MATCH:prdDatacenterLocation: CTX
[2018-06-08 08:01:11.104] [I] Variable Set to: CTX
[2018-06-08 08:01:11.107] [I] REGEX MATCH:prdProdOrNonProd: Production
[2018-06-08 08:01:11.110] [I] Variable Set to: Production
[2018-06-08 08:01:11.113] [I] REGEX MATCH:prdVMRole: Epic
[2018-06-08 08:01:11.116] [I] Variable Set to: Epic
FULL SCRIPT
-------------------------------------------------------------------------
if(payload != null) {
var sortKeys = payload.keys.sort()
sortKeys.forEach(function(key){ //foreach element in the array
logProperties(key, payload.get(key), "");
});
} else {
System.debug("Payload is null");
}
attPropertyArray = new Properties();
function logProperties(keyName, keyValue, keyParent) {
var keyValueType = System.getObjectType(keyValue);
if(keyValueType == "Properties") {
var sortKeys = keyValue.keys.sort()
sortKeys.forEach(function(k){
logProperties(k, keyValue.get(k), keyParent+keyName+".");
});
} else {
if(keyValue == "") {
keyValue = "null";
}
/* DOES NOT WORK
var expr = /prd/;
if(keyName.match(expr)) {
attPropertyArray.put(keyName,keyValue);
}
*/
var expr = /prdVMRole/;
if(keyName.match(expr)) {
//System.log(keyName + ': ' + keyValue);
prdVMRole = keyValue;
System.log("Variable Set to: " + prdVMRole);
}
var expr = /prdDatacenterLocation/;
if(keyName.match(expr)) {
//System.log(keyName + ': ' + keyValue);
prdDatacenterLocation = keyValue;
System.log("Variable Set to: " + prdDatacenterLocation);
}
var expr = /prdProdOrNonProd/;
if(keyName.match(expr)) {
//System.log(keyName + ': ' + keyValue);
prdProdOrNonProd = keyValue;
System.log("Variable Set to: " + prdProdOrNonProd);
}
//System.debug(keyParent + keyName + ":"+keyValueType+": " +keyValue);
}
}
attPropertyString = prdVMRolea + " " + prdDatacenterLocation + " " + prdProdOrNonProd
attPropertyArray.put("prdVMRole",prdVMRole);
attPropertyArray.put("prdDatacenterLocation",prdDatacenterLocation);
attPropertyArray.put("prdProdOrNonProd",prdProdOrNonProd);