Automatic generated e-mail

Hi everyone,

I need your support to finalize a short module which will be used to create the portals access for the newcomers.

Today the flow is not optimum and by using this module we want to avoid extra job generated by this activity which consists mostly in transfering e-mails from newcomers to IT department and from IT to newcomers once the accesses are created.

Here below, is the javascript that I have written by using useful exemple find thanks to this community but the final result is not the one that I expected.

var email="test@toyota-industries.eu";
var subject="Demande de création d'accès portails";
var body_start="Bonjour, Merci de bien vouloir donner accès aux portails ci-dessous à ";
var player = GetPlayer();
var body_end=" ";
var MSCO =" employé au sein de ";
var MSCO_end =" : ";
var name = player.GetVar("name1");
var lname = player.GetVar("Firstname");
var organization = player.GetVar("organization1");
var checkbox1 = player.GetVar("checkboxold");
var checkbox2 = player.GetVar("checkboxwp");
var checkbox3 = player.GetVar("checkboxsp");
var checkbox4 = player.GetVar("checkboxtt");
var checkbox5 = player.GetVar("checkboxiw");
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start + name + body_end + lname + MSCO + organization + MSCO_end + checkbox1 + checkbox2 + checkbox3 + checkbox4 + checkbox5; 
 win=window.open(mailto_link,'emailWin');

I would like to generate this automatic e-mail when the user will click on the button "Generate request e-mail":

"Hello, please provide the access to the portals listed below to John Doe from TMHE department :

-portal 1

-portal 2

-portal 3

-portal 4

-portal 5"

 

But today, with the actual javascript the result is like this:

"Hello, please provide the access to the portals listed below to John Doe from TMHE department : portal 1portal 2portal 3portal 4portal 5.

 

I have seen on google that to jump a line the instruction in javascript is \n but I don't know where to write it in my javascript.

Thank you for your support and your time spent to share your knowledge.

Cheers.

Julien

 

4 Replies
Matthew Bibby

Hi Julien,

Try changing this:

var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start + name + body_end + lname + MSCO + organization + MSCO_end + checkbox1 + checkbox2 + checkbox3 + checkbox4 + checkbox5; 

To this:

var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start + name + body_end + lname + MSCO + organization + MSCO_end + '/n/n' + checkbox1 + '/n/n' + checkbox2 + '/n/n' + checkbox3 + '/n/n' + checkbox4 + '/n/n' + checkbox5; 

Hopefully that'll do the trick.

Let me know if you run into any issues.

MERY Julien

Hi Matthew,

thank you for helping me to solve this issue. I have tried your solution but unfortunately it doesn't work.

I have found something else in the in the file story.js included in folder sotry_content once you have published the module and the instruction to jump to next line is used over a variable called :
 var strNewLine = "\n";
 if (IE)
 {
  strNewLine = "%0D%0A";
 }

I have used it in my javascript and everything worked well. The last negative point was the fact that even on box was unticked I had an empty line between two portals.

The solution was to add a condition to say that if the box is ticked so display portal + jump line but if the box is not ticked display nothing. The scrip is like this:

var strwp = player.GetVar("checkboxwp") !=  "" ? player.GetVar("checkboxwp")+crlf : "";

My new javascript looks like this and run perfecly:

var email="test@toyota-industries.eu";
var subject="Demande de création d'accès portails";
var crlf = "%0D%0A";
var strold = player.GetVar("checkboxold") != "" ? player.GetVar("checkboxold")+crlf : "";
var strwp = player.GetVar("checkboxwp") !=  "" ? player.GetVar("checkboxwp")+crlf : "";
var strsp = player.GetVar("checkboxsp") !=  "" ? player.GetVar("checkboxsp")+crlf : "";
var strtt = player.GetVar("checkboxtt") !=  "" ? player.GetVar("checkboxtt")+crlf : "";
var striw = player.GetVar("checkboxiw") !=  "" ? player.GetVar("checkboxiw")+crlf : "";
var body = "Bonjour," + crlf + "Merci de bien vouloir donner accès aux portails ci-dessous à " + player.GetVar("name1") + " "
+ player.GetVar("Firstname") + " employé au sein de "+ player.GetVar("organization1") + " : " + crlf + strold + strwp + strsp +  strtt + striw;
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body+ crlf +"Cordialement";
 win=window.open(mailto_link,'emailWin');

 

It took me two days of work to fix this issue but from a knowledge point of view it was really interesting and I hope that can help other users to solve similar issue.

Cheers.

Julien

Matthew Bibby

Hi Julien,

Sorry about that. On closer inspection of your code, I can see why my suggestion didn't work. 

I typically have a encodeURIComponent() function set up which encodes special characters, but you don't have that in your solution, which is why the /n didn't work for you. 

Great to see that you got it all sorted though! If you want more info on sending emails from SL, you might find this tutorial I wrote on the topic interesting.

 

MERY Julien

Hi Matthew,

 Thanks for helping me with your clear explanation, if I had a look on your tutorial before to start for sure it would have helped me to save time.

I will keep this link in my favorite as many explanation can be useful for my next development.

Regards.

Julien