Accessing data properties in array of dictionaries in Action Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 02:29 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 11:54 PM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 06:14 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:06 AM - edited 09-06-2024 07:07 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 12:00 PM
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!