- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 03:29 AM
Hello Experts,
I've created VirtualAgent main topic where I call topic block that performes survey. I'm trying to get answers from survey to use them in main topic. I managed to get object with answers and display it in the message but I have dificulties when it comes to using only value that is interesting for me - answer.
I've created this piece of code in message after survey:
(function execute() {
var obj = vaInputs.survey_answers.getValue();
obj = JSON.parse(obj);
var ans1 = Object.values(obj); //obj['526c28d787585110d1f7cb790cbb3516'].value;
return ans1;
})()
commented line works but I don't want to hardcode sys id's of questions in here.
Object looks like this:
{"526c28d787585110d1f7cb790cbb3516":{"value":false,"Qtype":"boolean","displayValue":false},"f449355f871c5110d1f7cb790cbb3509":{"value":null,"Qtype":"scale","displayValue":null}}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 04:20 AM
Hi,
Not sure of the question. Following will print out the values.
var obj = {"526c28d787585110d1f7cb790cbb3516":{"value":false,"Qtype":"boolean","displayValue":false},"f449355f871c5110d1f7cb790cbb3509":{"value":null,"Qtype":"scale","displayValue":null}}
for (var sysId in obj) {
var ans = obj[sysId].value;
gs.info(ans);
}
Execution result:
*** Script: false
*** Script: null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 03:37 AM
Hello,
Please first try this:
var myObject = { a: 'c', b: 'a', c: 'b' };
var keyNames = Object.keys(myObject);
console.log(keyNames); // Outputs ["a","b","c"]
and see whether you can get the sys_id.
Afterwards you will need to dot walk
myObject[keyNames].value
myObject[keyNames].Qtype
myObject[keyNames].displayValue
Hope this helps!
Tudor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 04:20 AM
Hi,
Not sure of the question. Following will print out the values.
var obj = {"526c28d787585110d1f7cb790cbb3516":{"value":false,"Qtype":"boolean","displayValue":false},"f449355f871c5110d1f7cb790cbb3509":{"value":null,"Qtype":"scale","displayValue":null}}
for (var sysId in obj) {
var ans = obj[sysId].value;
gs.info(ans);
}
Execution result:
*** Script: false
*** Script: null