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

email client template - how to use a dynamic FROM value?

Zod
Giga Guru

Hi All,

as I learned the hard way, just using mail scripts in the body (that will derive the proper from and reply_to values) will not work  

But ok ... for the reply to I can use some easy js like "javascript:current.assignment_group" .... BUT how to go ahead with more complex script which I need to define the FROM field?????

PLEASE HELP.

Best would be to be able to add a email script .. but this does not work (tried like in the body with ${mail_script:abc_scipt_client}

1 ACCEPTED SOLUTION

You can write a script include and call the script include in the java script. in script include, you can include the validation of assignment group.



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

21 REPLIES 21

does not work (maybe because of scoped app ... no idea).



I tried in the body:



${mail_script:csm_test_from}



and the mail script is set to:



(function runMailScript(current, template, email, email_action, event) {


email.setFrom("abc@xxxxx.com");                                         // valid email used


}) (current, template, email, email_action, event);


No. In the email body of client template, inside mail script tag, just type email.setFrom("abc@xxxxx.com");       . Don't use ${mail_script:


below is an example



<mail_script>


email.setFrom("abc@xxxxx.com");


var uname = current.user;




if (current.type != 'received') {


    var u = new GlideRecord('sys_user');


    uname = current.sys_created_by;


    if (u.get('user_name', uname))


          uname = u.name.toString() + '<' + u.email.toString() + '>';


}




var cdate = new Date();


cdate.setTime(current.sys_created_on.getGlideObject().getNumericValue());




var header = "On " + cdate.toLocaleString() + ", '" + uname + "' wrote:\n\n";


template.print(header);


if (current.body_text.isNil())


  template.print(current.body);


else


  template.print(current.body_text);


</mail_script>



Please mark this response as correct or helpful if it assisted you with your question.

I somehow do not fully understand.



Something like this should work then?


I need to use some client scripts .. and they are working fine currently.


Only the reply to and from field seem to be required to be set in the field directly.


emailclienttemplate_bodyscript.JPG


I get you now



use this ${mail_script:csm_test_from} in body then



and can you post a screen of the notification script. why are you using (function runMailScript(current, template, email, email_action, event) {



You can just write email.setFrom("abc@xxxxx.com");                                         // valid email used



Please mark this response as correct or helpful if it assisted you with your question.

I tried with the long mail script and it did NOT work.


So I want to know in general if a mail script can be used to set the FROM field ...



... here the mail_script


test_mail_script.JPG


and here the template


template.JPG


and here the log ;-(


log.JPG




I assume if it normally should work - it again is some scoped app limitation ;-(