cancel
Showing results for 
Search instead for 
Did you mean: 

Getting local task variable with Native Queries

rohitagrawal
Champ on-the-rise
Champ on-the-rise
Hi,

When use taskQuery with "includeTaskLocalVariables" i can get all task local variables.
But when i am using taskNativeQuery i don't get task local variables and also there doesn't seem to be any API.

List<Task> tasks = taskService.createNativeTaskQuery()
                 .sql("SELECT * FROM ACT_RU_TASK a, ACT_RU_VARIABLE b where b.NAME_='projectID' and b.TEXT_ in ('1','2')"  )
                   .list();

Please suggest

Regards
Rohit
6 REPLIES 6

trademak
Star Contributor
Star Contributor
That's correct, that functionality is not available on native query. Please raise a JIRA if you would like to see this being added.

Best regards,

rohitagrawal
Champ on-the-rise
Champ on-the-rise
is there any workaround to this.
Right now just to get task custom attributes(which is strictly required in our case) we need to fetch task again using taskService one by one.

jbarrez
Star Contributor
Star Contributor
No, the only workaround would be a direct mybatis query.

jbarrez
Star Contributor
Star Contributor
Actually, your post triggered me to make this easier in Activiti: http://www.jorambarrez.be/blog/2014/01/17/execute-custom-sql-in-activiti/

swamy2156
Champ on-the-rise
Champ on-the-rise
Jbarrez, thanks for providing simple solution like customSqlExecution feature. Its a big helping hand for me. How do I customize mapper with my own List<ResultType> instead of List<Map<String, Object>>? Could some one give an example for how to implement it.

Update: I find a way for this.
public class TaskResultType{

  private String name;
  private String id;

  public final void setName(final String name) {
    this.name = name;
  }

  public final String getName() {
    return name;
  }

  public final void setId(final String id) {
    this.id = id;
  }

  public final String getId() {
    return id;
  }
}
and the usage of return type as follows:

CustomSqlExecution<MyTestMapper, List<TaskResultType>> customSqlExecution =
        new AbstractCustomSqlExecution<MyTestMapper, List<TaskResultType>>(MyTestMapper.class) {

          public List<TaskResultType> execute(final MyTestMapper customMapper) {
            return customMapper.selectTasks();
          }

        };

    List<TaskResultType> results = managementService.executeCustomSql(customSqlExecution);


-Swamy.

jbarrez
Star Contributor
Star Contributor
Indeed - thanks for posting this back!