How to update a variable

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2016 05:27 AM
Hi everyone I created a variable in a serviceTask.
It's written Variables | 1 variables configured
I want to update this variable when she pass in my serviceTask with the java code below
public class myAuthTest implements JavaDelegate{
@Autowired
protected UserService userService ;
protected TaskService taskService ;
protected RuntimeService runtimeService ;
protected DelegateTask delegateTask ;
@Override
public void execute(DelegateExecution execution) throws Exception {
returnVariable(execution) ;
//taskService.setVariable("apl1", "myUserNamex",x);
//taskService.setVariable("apl2", "myUserNamey",x);
}
public String returnVariable(DelegateExecution execution){
User currentUser = SecurityUtils.getCurrentUserObject();
String x = currentUser.getExternalId();
Object yousra = execution.getVariable("myUserName") ;
execution.createVariableLocal("myUserName1",yousra) ;
yousra = (Object)x ;
execution.createVariableLocal("myUserName2",yousra) ;
return (String) yousra;
}
}
But I get a nullPointerException when i call my variable "myUserName" in a rest call inside my process
but when i go in postman using restAPI i can see my variables in my process using
http://xxxxxxx:9090/activiti-app/api/runtime/process-instances/xxxxxxxxxxx/variables?
This is returning me
[
{
"name": "myUserName1",
"value": null,
"scope": "local"
},
{
"name": "jobtitle",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "initiator",
"value": "7",
"scope": "local",
"type": "string"
},
{
"name": "job",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "nom",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "prenom",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "myUserName2",
"value": "administrator",
"scope": "local",
"type": "string"
},
{
"name": "email",
"value": "32505",
"scope": "local",
"type": "string"
}
]
myUserName1 is my variable before i update her
myUserName2 is my variable after i update her
But when I call it in a restAPI I get a nullPointerException
Someone can show me how to update a variable defined in the workflow ?
It's written Variables | 1 variables configured
I want to update this variable when she pass in my serviceTask with the java code below
public class myAuthTest implements JavaDelegate{
@Autowired
protected UserService userService ;
protected TaskService taskService ;
protected RuntimeService runtimeService ;
protected DelegateTask delegateTask ;
@Override
public void execute(DelegateExecution execution) throws Exception {
returnVariable(execution) ;
//taskService.setVariable("apl1", "myUserNamex",x);
//taskService.setVariable("apl2", "myUserNamey",x);
}
public String returnVariable(DelegateExecution execution){
User currentUser = SecurityUtils.getCurrentUserObject();
String x = currentUser.getExternalId();
Object yousra = execution.getVariable("myUserName") ;
execution.createVariableLocal("myUserName1",yousra) ;
yousra = (Object)x ;
execution.createVariableLocal("myUserName2",yousra) ;
return (String) yousra;
}
}
But I get a nullPointerException when i call my variable "myUserName" in a rest call inside my process
but when i go in postman using restAPI i can see my variables in my process using
http://xxxxxxx:9090/activiti-app/api/runtime/process-instances/xxxxxxxxxxx/variables?
This is returning me
[
{
"name": "myUserName1",
"value": null,
"scope": "local"
},
{
"name": "jobtitle",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "initiator",
"value": "7",
"scope": "local",
"type": "string"
},
{
"name": "job",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "nom",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "prenom",
"value": "32505",
"scope": "local",
"type": "string"
},
{
"name": "myUserName2",
"value": "administrator",
"scope": "local",
"type": "string"
},
{
"name": "email",
"value": "32505",
"scope": "local",
"type": "string"
}
]
myUserName1 is my variable before i update her
myUserName2 is my variable after i update her
But when I call it in a restAPI I get a nullPointerException
Someone can show me how to update a variable defined in the workflow ?
Labels:
- Labels:
-
Archive
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2016 05:28 AM
Hello,
I'm working in r&d and we are actually testing some activiti workflow
for our test we also need to use the variable system but we still can't use them
Looking throught internet this is the only topic where we are talking about the same problems
as this topic is fresh I'm would like to ask the same question
thanks
Julietta
I'm working in r&d and we are actually testing some activiti workflow
for our test we also need to use the variable system but we still can't use them
Looking throught internet this is the only topic where we are talking about the same problems
as this topic is fresh I'm would like to ask the same question
thanks

Julietta
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016 05:20 AM
@madn: if you define a variable like that in the service task properties, it means that your service task will set that variables in the execute() method. It is kinda like 'metadata' for your service task.
Instead of using createVariableLocal … why arent you using the setVariable() method?
Instead of using createVariableLocal … why arent you using the setVariable() method?
