Check for value exist in array

I have a external task that returns a array of objects and I like to see if a value exist in that array

The array returned is [{Name:“token1”,Id=“1”}, {Name:“token2”,Id=“2”}]

And I want a script that return true if token2 exists

image

I’ve tried something like this but response always return false

Well, the problem is you can’t use the SPIN-Library like the JavaScript JSON-Library.
Despites this your for-loop is not an foreach-loop, so you have to use the index value “i” in the loop itself on the element “tags”…

This code should workapproach would be this code:

var tags = S(execution.getVariable('CustomerTags'));
var response = false;
for (var i = 0; i < tags.elements().length; i++)
{
  if (tags.elements().get(i).prop('Name').value() == 'MVPGloria')
  {
    response = true;
    break;
  }
}
execution.setVariable('Filter', response);

Alternative with jsonPath (slower but less code):

var tags = S(execution.getVariable('CustomerTags'));
var response = tags.jsonPath('$[?(@.Name==\'MVPGloria\')]').elementList().length > 0;
execution.setVariable('Filter', response);