The CreatorCon Call for Content is officially open! Get started here.

Mail Scripts and the email Object

brian-rowland
Mega Contributor

I'm working on a complex email notification and I'm looking for information on the "email" object that's available from within mail_script tags. My immediate concern is updating/overriding the recipient list of the generated sys_email record. So far I've managed to dump the members/method names of the email object (instance of Java class EmailOutbound) and start cobbling together a little API for it. Unfortunately, it seems like many of the setter methods don't to do anything. Can someone shed light on the following methods, or direct me to the API for the class com.glide.notification.outbound.EmailOutbound? My hope is that I'm just passing in the wrong parameter types, since I'm guessing them. Thanks much.

addAddress()
setAddress()
setRecipients()

11 REPLIES 11

We'll be on Berlin in less than a month. Will this work with the notification subscribers on that version?


I think this needs to be slightly different:



if (!current.watch_list.nil()) {


  //get watch list addresses and add to cc


  var watchers = current.watch_list.split(",");


  var wl = watchers.length;



  for (var i = 0; i < wl; i++) {


  if (watchers[i].indexOf("@") != -1) {


  email.addAddress("cc", watchers[i], "");


  }


  else {


  //get user record


  var user = new GlideRecord("sys_user");


  user.addQuery("sys_id", watchers[i]);


  user.addQuery("notification", 2);


  user.addQuery("email", "!=", "");


  user.query();



  while (user.next()) {


  //add to cc list


  email.addAddress("cc", user.email, user.getDisplayValue());


  }


  }


  }


  }



Note the [i] within the loop. The original code did not work for me, as soon as i added the reference to the object being looped, it worked like a charm...



Thanks for the base script though!