How to enrich json array data before it will be loaded in camunda form?

I want to enrich json array data before it will be loaded in camunda form, service will give me json response with several property and based on startDate end endDate parameters i shoud add priority property to my json Data , when i try to use jsonDate camunda throws me exception that JsonData isn’t defined here is my code exmaple:

camForm.on('form-loaded', function() {
    
      camForm.variableManager.fetchVariable('jsonData');
    });
    camForm.on('variables-fetched', function() {
      $scope.jsonData = camForm.variableManager.variableValue('jsonData');
    });

//make  effort  for  priority

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = mm + '/' + dd + '/' + yyyy;
function normalDate(rawData){

var today = new Date(rawData);
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = mm + '/' + dd + '/' + yyyy;
return today;
}
for(var  i=0;i<Object.keys(jsonData);i++){
jsonData[i].startDate=normalDate(jsonData[i].startDate);
jsonData[i].endDate=normalDate(jsonData[i].endDate);
var  between=new Date(jsonData[i].endtDate).getTime()-new Date(jsonData[i].startDate).getTime();
console.log(between);
if(between<2 || between ==0 && between==today){
jsonData[i].priority='very important';
}
else  if(between<3){
jsonData[i].priority='important';
}
else{
jsonData[i].priority='not  so  important';
}
console.log(jsonData);
}

what shoudl i change to make camVariable avalaible?

Hi @Sally,

you could change the value of the process variable jsonData in the below function.

Example:

camForm.on(‘variables-fetched’, function() {
var jsonData = camForm.variableManager.variableValue(‘jsonData’);
$scope.jsonData = enrichJsonDataVar();
});

Cheers
kristin

hi @kristin thank you for your reply in this case i will have to paste all this code:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = mm + '/' + dd + '/' + yyyy;
function normalDate(rawData){

var today = new Date(rawData);
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = mm + '/' + dd + '/' + yyyy;
return today; 
...

inside enrichJsonDataVar(); function and this will change data before it will be placed into form?
@kristin i have tried this but i got this error : :8080/camunda/lib/deps.js?bust=7.8.0:33142 ReferenceError: jsonData is not defined
** at enrichJsonDataVar (eval at ** what should i change, to get rid of this error?

@kristin thank you your advice was very helpful i have made this task :slight_smile: