cancel
Showing results for 
Search instead for 
Did you mean: 

Email notification on a datalist advanced task

naas79
Champ in-the-making
Champ in-the-making
Hi, first of all, I'm new on alfresco, and I'm not a developer, so maybe my question can be obvious for a lot of people.
I'm using alfresco community 4.2f on a linux ubuntu 14 platform and I'm testing some features like datalists.
I wrote a javascript to send emails when an advanced task is created in a datalist, to users who are assigned to.To do this I use a rule on the datalist directory and a javascript.
Here's the code below :
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
var person=document.assocs["dl:taskAssignee"][0];
var username=person.properties["{http://www.alfresco.org/model/content/1.0}userName"];
var email = person.properties.email
// create mail action

var mail = actions.create("mail");


mail.parameters.to = email;

mail.parameters.subject = "Nouveau document déposé";

mail.parameters.from = "admin@alfresco";

mail.parameters.template = companyhome.childByNamePath("mytemplate");

mail.parameters.text = some text;


mail.execute(person);
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

If I've 2,3 persons assigned to an advanced task, an email is sent only to the first user assigned but not to the others.
I think I need a "for loop" to get all assignees in "dl:taskassignee" but i don't know how to do that.

If somebody got an idea, I'll be really greatfull.
Regards.

Emmanuel Naas.
6 REPLIES 6

pkie
Champ in-the-making
Champ in-the-making
Did You try something like this, for the loop?

<javascript>
for(var person in document.assocs["dl:taskAssignee"])
{
    //your code
}
</javascript>

Regards,

naas79
Champ in-the-making
Champ in-the-making
I try it, but I receive the mail twice for the first user and nothing for the others.
But I'm pretty sure I've made a mistake.
I have tried to do like this :
#####################################################

for(var person in document.assocs["dl:taskAssignee"])
{
var person=document.assocs["dl:taskAssignee"][0];
var username=person.properties["{http://www.alfresco.org/model/content/1.0}userName"];
var email = person.properties.email
// create mail action

var mail = actions.create("mail");


mail.parameters.to = email;

mail.parameters.subject = "Nouveau document déposé";

mail.parameters.from = "admin@alfresco.com";

mail.parameters.template = companyhome.childByNamePath("mytemplate");

mail.parameters.text = username;

mail.execute(person);
}
###############################################

thanks for you're help

naas79
Champ in-the-making
Champ in-the-making
It works, I've tried this, enad it's OK.
thanks a lot, for your help.

#################################################
var person=document.assocs["dl:taskAssignee"][0];

for each (person in document.assocs["dl:taskAssignee"])
{
var email = person.properties.email
var username=person.properties["{http://www.alfresco.org/model/content/1.0}userName"];
var mail = actions.create("mail");
mail.parameters.to = email;
mail.parameters.subject = "Nouveau document déposé";
mail.parameters.from = "admin@alfresco";
mail.parameters.text = username;
mail.execute(person);
}
############################################################

pkie
Champ in-the-making
Champ in-the-making
<javascript>
var person=document.assocs["dl:taskAssignee"][0];

for each (person in document.assocs["dl:taskAssignee"])
</javascript>

the first line is unnecesary - it just puts to var person the first taskassignee association, and it is overwriten in the for each loop.

so it should look like:
<javascript>
for(var person in document.assocs["dl:taskAssignee"])
{
   var email = person.properties.email
   var username=person.properties["{http://www.alfresco.org/model/content/1.0}userName"];
   var mail = actions.create("mail");
   mail.parameters.to = email;
   mail.parameters.subject = "Nouveau document déposé";
   mail.parameters.from = "admin@alfresco";
   mail.parameters.text = username;
   mail.execute(person);
}
</javascript>

naas79
Champ in-the-making
Champ in-the-making
Thanks for the return.I've erase the line, it works fine.
Thanks a lot.

naas79
Champ in-the-making
Champ in-the-making
An other quick question.
I found on the wiki JavascriptAPI cook book some code to create datalist.
It works fine and i succeed to custom it form my needs, the only thing, I don't know how to make a automatic association attachment.
I've created a custom datalist type, it works fine. In the document library i've created a directory with a rules, and when I put a document in this directory, the script create a datalist item in my custom datalist.
Everything is ok, but I would like my script create a attachment with the document in the datalist.
I hope I'm clear, my english is not perfect and as you know, french guys are bad in english.
Nevertheless, if you a some advice about my problem that will be great 🙂