Expression based hands on:
a) Given 4 dictionaries of the students data with id, name and city, remove the students who belong to the city Pune.
b) Update the data: change the city name Mumbai to Bangalore.
Sample data:
local!students: { a!map(id: 1, name: "John", city: "Pune"), a!map(id: 2, name: "Sam", city: "Mumbai"), a!map(id: 3, name: "Ravi", city: "Pune"), a!map(id: 4, name: "Anu", city: "Delhi")}
Expression based hands on:
a) Given 4 dictionaries of the students data with id, name and city, remove the students who belong to the city Pune.
b) Update the data: change the city name Mumbai to Bangalore.
Sample data:
Answer
a) Solution :
Output :

Explanation :
This expression defines a list of students using a!localVariables, then removes all students whose city is "Pune". It first uses index() to extract all city values from the student list, resulting in something like {"Pune", "Mumbai", "Pune", "Delhi"}. Then wherecontains() finds the positions where "Pune" appears (positions 1 and 3). Finally, remove() deletes the students at those positions from the original list. As a result, only the students from Mumbai and Delhi remain.
b) Solution:
Output:

Explanation :
This expression defines a list of students and then loops through each student using a!forEach. For every student, it checks if the city is "Mumbai". If the condition is true, it uses a!update() to change the city value to "Bangalore"; otherwise, it keeps the student data unchanged. As a result, only the student(s) from Mumbai will have their city updated to Bangalore, while all others remain the same.
Try it yourself
Change the inputs or the expression and run it to see what it returns.
Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms