Klaus.Nuber

Can't iterate over result of convertJson()

Discussion created by Klaus.Nuber on Jul 8, 2016
Latest reply on Jul 12, 2016 by Klaus.Nuber

Hi all,

we found an incosistency in the javascript implementation in the Run Javascript operator in PAM

 

Iteration over object properties works on “normal” JavaScript objects but not on objects returned by convertJson().

 

Javascript code in Run Javascript operator:

 

var output = "";

 

output += "Object, for-in loop\n";

var obj = {"key1" :"value1","key2" :"value2"};

for( var key in obj ) {

  if( obj.hasOwnProperty( key ) ) {

     output += "Key: " + key + " Value: " + obj[key] + "\n";

  }

}

output += "\n";

 

output += "Object from convertJson(), for-in loop\n";

var jsonObj = convertJson("{\"key1\" :\"value1\",\"key2\" :\"value2\"}" );

for( var key in jsonObj ) {

  if( jsonObj.hasOwnProperty( key ) ) {

     output += "Key: " + key + " Value: " + jsonObj[key] + "\n";

  }

}

output += "\n";

 

output += "Object from convertJson(), direct property access\n";

var key = "key1";

output += "Key: " + key + " Value: " + jsonObj[key] + "\n";

key = "key2";

output += "Key: " + key + " Value: " + jsonObj[key] + "\n";

 

Process.Output = output;

 

 

Output:

 

Object, for-in loop

Key: key1 Value: value1

Key: key2 Value: value2

 

Object from convertJson(), for-in loop

 

Object from convertJson(), direct property access

Key: key1 Value: value1

Key: key2 Value: value2

 

Version:

CA Process Automation 4.3

 

Version: 4.3 HF01
Build: 4.3.50 HF01 - Aug 11, 2015 3:16:12 PM

Outcomes