Hello, I am a beginner Bonita BPM 7, I did a leave request process, I made two model of business data DemandesConges (StartDate, EndDate, dateRetours, NombreJours, TypeConge, balance, MotifConge) and DossierAdministratif (firstName, lastName, Email…), now I want to know how I can calculate balance of leave in such a way that whenever an employee is applying for leave, the balance of leave subtracts the number of days.
I made a script for the variable of pool but plenty of error
import com.company.model.DemandesConges
import com.company.model.DemandesCongesDAO
import org.bonitasoft.engine.api.*
import org.bonitasoft.engine.api.IdentityAPI
import org.bonitasoft.engine.bdm.BusinessObjectDAOFactory
import org.bonitasoft.engine.business.data.SimpleBusinessDataReference
import org.bonitasoft.engine.identity.User
import org.bonitasoft.engine.identity.UserCriterion
import org.bonitasoft.engine.session.APISession
def demandesCongesVar = new com.company.model.DemandesConges()
demandesCongesVar.dateDebut = demandeInput.dateDebut
demandesCongesVar.nombreJours = demandeInput.nombreJours
demandesCongesVar.typeConge = demandeInput.typeConge
demandesCongesVar.motifConge = demandeInput.motifConge
demandesCongesVar.dateFin = demandeInput.dateFin
demandesCongesVar.dateRetours = demandeInput.dateRetours
if(demandesCongesVar.getTypeConge()==“payé”)
{
demandesCongesVar.solde = 22}
else if(demandesCongesVar.getTypeConge()==“maternité”){
demandesCongesVar.solde = 60
}
else if(demandesCongesVar.getTypeConge()==“impayé”){
demandesCongesVar.solde = 20
}else if(demandesCongesVar.getTypeConge()==“paternité”){
demandesCongesVar.solde = 3
}
else if(demandesCongesVar.getTypeConge()==“maladie”){
demandesCongesVar.solde = 25
}
else{
demandesCongesVar.solde = 15
}
double solde = demandesCongesVar.getSolde()
solde = solde - demandesCongesVar.getNombreJours()
demandesCongesVar.setSolde(solde)
demandesCongesVar.getPersistenceId()
def apiSession = PageContext.getApiSession();
BusinessDataAPI businessDataAPI = BusinessDataAPI.getBusinessDataAPI(apiSession);
// Use BusinessDataAPI to retrieve the process instance business variable
// We need to cast it to the appropriate class (SimpleBusinessDataReference or MultipleBusinessDataReference)
SimpleBusinessDataReference businessDataReference = (SimpleBusinessDataReference)businessDataAPI.getProcessBusinessDataReference(“vacationAvailable”, 2);
// Get storage id (i.e. persistence id) of the business variable
Long storageId = businessDataReference.getStorageId();
// Create DAO factory for the business data
BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();
DemandesCongesDAO demandesCongesDAO = daoFactory.createDAO(apiSession, DemandesCongesDAO.class);
// Use DAO to find the business variable using the storage id (i.e. persistence id)
DemandesConges demandesConges = demandesCongesDAO.findByPersistenceId(storageId);
//Use the factory to obtain a DAO object
IdentityAPI identityAPI = apiAccessor.identityAPI
List<User> users
// For each user
for(DemandesConges demande: demandesConges){
double soldeEncours=demandesConges.getSolde()
return soldeEncours
demandesCongesVar.setSolde(soldeEncours)
}
def processInstance = apiAccessor.processAPI.getProcessInstance(processInstanceId)
// Ajouter l’identifiant du demandeur à la nouvelle demande
demandesCongesVar.idDemandeur = processInstance.startedBy
return demandesCongesVar