xpagesxpages-ssjs

Getting a subset of string from multivalue field SSJS


In an XPage bound to a document I have a multivalue field containing email addresses. I simply wish to loop through the email addresses and return a subset of addresses which contain mydomain. To then use them in 'recipient' field for emailing.

Seems straight forward, but I receive the following error, even though 'typeof()' returns strings. I can't seem to get away from the [JavaScript Object]. Tried toString() and all sorts. Any help is appreciated.

Error message Error while executing JavaScript computed expression Script interpreter error[TypeError] Error calling method 'includes(string)' on an object of type 'String [JavaScript Object]'

JavaScript code

  var array = documentContract.getItemValueArray("EmailAddress")
  var result = "";
  for (var i=0; i<array.length; i++) {
  if ( array[i].includes("@mydomain.com"))  { 
  result = result + array[i] + "\n";}
  }
  return result;

Solution

  • The error message says that includes is not an available method on the string object.

    You can use @Contains:

    if (@Contains(array[i], "@mydomain.com"))  {