cancel
Showing results for 
Search instead for 
Did you mean: 

if else if scripting in sap cai

former_member671720
Participant
0 Kudos

Hi,


I am doing a API request and getting an array as response and I want to compare the array entries something like

currently i am restricted to compare only one value,

how to include multiple conditions like nested if conditions,

do we have nested scripting in CAI where i can compare multiple values and show output accordingly

and also how can use variable of variable for ex. results[number] where results is an array and number is an variable initialized in the memory, something like : {{results[ {{number}} ]}}

Thanks
Kishore

Accepted Solutions (1)

Accepted Solutions (1)

JonasB
Contributor
0 Kudos

Hi Kishore,

you can actually chain the conditions by using "{{else eq api_service_response.... '02'}}".
See the handlebars documentation for details: https://handlebarsjs.com/guide/block-helpers.html#conditionals. I'll check if it makes sense to add this to the scripting documentation.

Regarding your second question, you can use the "itemAt" helper to access an array element dynamically, e.g, "{{itemAt results number}}".

Regards
Jonas

former_member715858
Participant
0 Kudos

Hi,

I am trying to consume the following file

https://sampleserver5.arcgisonline.com/arcgis/rest/services/?f=pjson

I need to get records when the "type": "MapServer". I tried to use the if condition and with but without success,

{ "type": "carousel", "delay": "", "content": [ {{#eachJoin api_service_response.default.body.services}} { "title": "{{name}}", "subtitle": "$ {{type}}", "imageUrl": "", "buttons": [ { "title": "Buy", "value": "Buy", "type": "postback" } ] }{{/eachJoin}} ] }

can you advise pls

Answers (0)