Email notification to someone who is not task handler

Discuss problems installing or using TrackStudio.

Email notification to someone who is not task handler

Postby Simon H » Sat May 07, 2011 1:48 pm

Our requirement
We have implemented a Questions System where anyone can ask a question by posting an operation to a task.
  • The user create the Question set the operation assignee to the person they want to ask
  • The person who is asked is sent an e-mail notification
  • The person who is asked is set as "Informat", which is a task UDF field
  • Importantly the task assignee is not changed

Implementation in TS 3
A before add message script does as follows
  • Sets message.udf.informant = message.assignee
  • Sets message.assignee = task.assignee
Which works perfectly

Behaviour in TS 4
The email notificartion gets sent to task.assignee (who is usually the person asking the question!), not message.assignee

First attempt at fix
Before add message script
  • Sets message.udf.informant = task.assignee

After add message script
  • Sets task.assignee = message.udf.informant (puts task.assignee back to original value)
  • Sets message.udf.informant = message.assignee
This errors on set task.assignee. The following code
Code: Select all
AdapterManager.getInstance().getSecuredTaskAdapterManager().updateTask(message.getSecure(), task.getId(), task.getShortname(), task.getName(), task.getDescription(), task.getBudget(), task.getDeadline(), task.getPriorityId(), task.getParentId(),
 assignee, null, false);

produces error: "com.trackstudio.exception.GranException: Could not execute JDBC batch update"
If the handlerUserId paremeter is set to null there is no error, but also there is not point in calling the method.

Second attempt at fix
Create the e-mail in before add message script.
From searching the forum I gather than JavaMail has to be used.
JavaMail cannot use templates :( , but we can live with that.
But
  • How do we access and use JavaMail?
  • How do I access the Config object in order to getSiteURL() to provide a link to the task in the e-mail?

Would you please suggest a better solution, identify where I am going wrong in the first attempt or, as last resort, give an example of creating an e-mail in a trigger. Many thanks in advance.
Simon
Simon H
 
Posts: 51
Joined: Mon Aug 13, 2007 12:23 pm

Re: Email notification to someone who is not task handler

Postby admin » Wed May 11, 2011 12:50 am

Sorry, I don't understand the problem in such format :(

Can you send me
1) Anonymized database backup
2) What script should do, in detail
3) Your 3.5 script, which works fine.
Maxim Kramarenko (mailto: maximkr@trackstudio.com)
TrackStudio - Hierarchical Bug & Issue Tracking Software
http://www.trackstudio.com
admin
Site Admin
 
Posts: 8148
Joined: Thu Jan 01, 1970 3:00 am
Location: Smolensk, Russia

Re: Email notification to someone who is not task handler

Postby Simon H » Thu May 19, 2011 9:30 am

Thank-you for your reply, Maxim. I tried to fix this again and succeeded this time. I think the problem was with the filter used by the e-mail notification rather than the script.

Nonetheless it would be most useful to know how to do the following in a trigger script:
- Send an e-mail
- Change the task assignee
Simon H
 
Posts: 51
Joined: Mon Aug 13, 2007 12:23 pm

Re: Email notification to someone who is not task handler

Postby Petr » Thu May 19, 2011 5:10 pm

Send an e-mail

What is mean? You can sent the email if you do something action add task/edit/add message/add attachment.
Change the task assignee

like this.
Code: Select all
task.setHandlerUserId(userId);
Стань Java программистом с www.job4j.ru
Petr
 
Posts: 2929
Joined: Wed Aug 12, 2009 4:38 pm

Re: Email notification to someone who is not task handler

Postby Simon H » Mon May 23, 2011 2:03 pm

Method setHandlerUserId( java.lang.String ) not found in class'com.trackstudio.secured.SecuredTaskBean'

Code used in after message script
Code: Select all
theId = ...........................
Object task = message.getTask();
task.setHandlerUserId(theId);
Simon H
 
Posts: 51
Joined: Mon Aug 13, 2007 12:23 pm

Re: Email notification to someone who is not task handler

Postby Petr » Mon May 23, 2011 2:24 pm

Yes. I was wrong. So Do you want to set the handler for task. Am I right?
You need update task. like this
Code: Select all
KernelManager.getTask().updateTask(taskId, SafeString.createSafeString(shortName), SafeString.createSafeString(name1), SafeString.createSafeString(description), budget1, deadline,
                priorityId1, parentTaskId, handlerUserId1, handlerGroupId1, submitDate, updateDate);

where handlerUserId1 - is user ID, and handlerGroupId1 - is prstatus Id the same role user Id.
Стань Java программистом с www.job4j.ru
Petr
 
Posts: 2929
Joined: Wed Aug 12, 2009 4:38 pm

Re: Email notification to someone who is not task handler

Postby Simon H » Sun Feb 26, 2012 4:45 am

I gave up with this last year but it is still causing us problems.

I am trying to set the handler for the task, everything else works.

This code runs but I do not want to set the task handler to the message handler
Code: Select all
AdapterManager.getInstance().getSecuredTaskAdapterManager().updateTask(message.getSecure(), task.getId(), task.getShortname(), task.getName(),
task.getDescription(), task.getBudget(), task.getDeadline(), task.getPriorityId(), task.getParentId(),
message.getHandlerUserId(), message.getHandlerGroupId(), false);


What I am doing is
- in BEFORE trigger reading the task handler and saving it is UDF fields
- in AFTER trigger reading UDF fields and setting task handler back to what it was originally

In the before trigger I successfully get the UserID using
Code: Select all
message.getTask().getHandlerUserID()

However the following code which I hoped would return the return the prstatus returns blank (not sure whether null or blank string)
Code: Select all
message.getTask().getHandlerGroupID()


Is it possible to obtain a prstatus from a UserID? That might be easier than saving UserID AND Prstatus.

I am sure I am missing something simple and would be really grateful if it were pointed out.
Simon H
 
Posts: 51
Joined: Mon Aug 13, 2007 12:23 pm

Re: Email notification to someone who is not task handler

Postby admin » Sun Feb 26, 2012 5:40 pm

Actually, getHandlerGroupId return something, if task assigned to role, not user. So, to get user group, you should get user first, and then get it's role set for some specific task.

Note that user can have multiple roles and set can be different for different tasks.
Maxim Kramarenko (mailto: maximkr@trackstudio.com)
TrackStudio - Hierarchical Bug & Issue Tracking Software
http://www.trackstudio.com
admin
Site Admin
 
Posts: 8148
Joined: Thu Jan 01, 1970 3:00 am
Location: Smolensk, Russia

Re: Email notification to someone who is not task handler

Postby Simon H » Mon Feb 27, 2012 2:59 pm

All our tasks are assigned to a user not a role.

So, to get user group, you should get user first,

I have UserID
and then get it's role set for some specific task.

how do I do this from the UserID, please?
Simon H
 
Posts: 51
Joined: Mon Aug 13, 2007 12:23 pm

Re: Email notification to someone who is not task handler

Postby Petr » Thu Mar 01, 2012 3:20 pm

Hello. You can do it like this:
Code: Select all
String userId = //get user id from anything
SecuredUserBean user = new SecuredUserBean(sc, userId);
String prstatusId = user.getPrstatusId(); // this is it what you asked
Стань Java программистом с www.job4j.ru
Petr
 
Posts: 2929
Joined: Wed Aug 12, 2009 4:38 pm


Return to TrackStudio Support

Who is online

Users browsing this forum: No registered users and 6 guests

cron