Accessing data properties in array of dictionaries in Action Script

lonesoac01
Giga Guru

Hello all,

 

   I am trying to access properties of dictionaries in an Action Script.  Here is the basic array structure:

 

[ {
  "is_bot" : "false",
  "participantId" : "f09b5accdbd35700ba385ce2ca96197d",
  "participantType" : "CLIENT"
}, {
  "is_bot" : "true",
  "participantId" : "system",
  "participantType" : "AGENT"
}, {
  "is_bot" : "true",
  "participantId" : "4aa85185dbef10105113a09e13961941",
  "participantType" : "AGENT"
} ]

My ultimate goal is to transform the string true/false into boolean data types.  How can I do this?

4 REPLIES 4

debendudas
Mega Sage

Hi @lonesoac01 ,

You can use the below script:

var array = [ {
  "is_bot" : "false",
  "participantId" : "f09b5accdbd35700ba385ce2ca96197d",
  "participantType" : "CLIENT"
}, {
  "is_bot" : "true",
  "participantId" : "system",
  "participantType" : "AGENT"
}, {
  "is_bot" : "true",
  "participantId" : "4aa85185dbef10105113a09e13961941",
  "participantType" : "AGENT"
} ];

for(item in array){
	array[item].is_bot = (array[item].is_bot == "true"); //changing String value to Boolean
}
gs.print(JSON.stringify(array)); // This is the final array with Boolean values

……………………………………………………………………………………………………

Please Mark it helpful  👍 and Accept Solution ✔️ !!!! If this helps you!!

I implemented the code you suggested and this is the error code I am seeing:

 

{
    "Step Status": {
        "code": 1,
        "message": "Error: Java class \"com.snc.cobject.ComplexObject\" has no public instance field or method named \"is_bot\". (Process Automation.b03528e89364d610b93bc2e548373c6b; line 4)"
    }
}

 

This is the exact code I am using:

(function execute(inputs, outputs) {
    var participants = inputs.parameter1
    for (item in participants) {
        participants[item].is_bot = (participants[item].is_bot == "true"); //changing String value to Boolean
    }
})(inputs, outputs);

 

Here is a screenshot of the Script Action:

lonesoac01_0-1725628446428.png

 

Hi @lonesoac01 ,

I think not all of our array object has the "is_bot" property.

Try with the below script and let me know if it works:

 

(function execute(inputs, outputs) {
    var participants = inputs.parameter1
    for (item in participants) {
        if(participants[item].hasOwnProperty("is_bot")){
            participants[item].is_bot = (participants[item].is_bot == "true"); //changing String value to Boolean
        }
    }
})(inputs, outputs);

 

 

Hi @lonesoac01 ,

Did you get any updates?

 

Please mark my answer as correct and helpful, and give it a like if it helped you. This will show that your question is answered and can help others too.

 

Thanks!