Available days leave request Bonita BPM7?

I created a process for employees to request leave in Bonita Bpm 7. I want to know how can I show available days for a request.
Here is what I have so far:
Dropbox https://www.dropbox.com/s/1krab4fgauvluc5/DemandeConge.bos?dl=0

Create a Custom Query in the BDM and call it selectNombreJoursSolde

SELECT s FROM soldeConge s WHERE s.idDemandeur = :idDemandeur ORDER BY s.persistenceId DESC

DESC means you will always get the last one

Change the return type to Single (of type BDM)

and then in your form add a variable calling REST query as follows:

…/API/bdm/businessData/com.company.model.soldeConge?q=selectNombreJoursSolde&p=0&c=1000&f=idDemandeur={{idDemandeur}}

You should then be able to show the data on the form

regards
Seán

PS: As this reply offers an answer your question, and if you like it, please Mark UP and/or as Resolved.

@sean McP Thank you very much to your reply but I’am confused I asked about groovy script , how can I store the available leave days. I have already defined a process with business data where in a first step a user can create a leave request. In the next step the available leave days of the user are decreasing and are shown in a formular to a manager who can approve (if the employee has enough leave days left) .
I figured out that business data would be a good way to model this scenario. I am thinking to create two business objects, an employee object and a leave request object. My question now is: How to I store the available leave days of an employee using business data I somehow have to pre-fill the business data databank, so every employee has some leave days available.
I am using Bonita 7.4 Performance With available leave days i mean the days which an employee has available over the course of a year to go on vacation.
how can I do this, to calculate availabledays(solde) of the user

I confused ,I do this but not work
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
int solde = demandeInput.solde
solde = solde - demandeInput.nombreJours
demandesCongesVar.setSolde(solde)
def processInstance = apiAccessor.processAPI.getProcessInstance(processInstanceId)
// Ajouter l’identifiant du demandeur à la nouvelle demande
demandesCongesVar.idDemandeur = processInstance.startedBy
import org.bonitasoft.engine.api.IdentityAPI
import org.bonitasoft.engine.identity.User
import org.bonitasoft.engine.identity.UserCriterion
import com.company.model.DemandesConges

// Default vacations days number
final int daysAvailableInitialValue = 60

// Offset and increment to use when using paginated API
int offset = 0
int increment = 10

// The list of Bonita BPM user id that already have an entry in VacationAvailable table
List alreadyKnownEmployeeId = new ArrayList()

// The list of already created VacationAvailaible
List currentlyExistingDemandesConges

// The newly created VacationAvailable
List newDemandesConges = new ArrayList()

// Search for already existing VacationAvailable counters
while ((currentlyExistingDemandesConges = DemandesCongesDAO.find(offset, increment)).size() > 0) {
for (DemandesConges va : currentlyExistingDemandesConges) {
// Update the list of user ids for user who already have an associated VacationAvailable object
alreadyKnownEmployeeId.add(va.bonitaBPMId)

	// Reset the vacation available counter
	va.solde=daysAvailableInitialValue
}

offset += increment

}

IdentityAPI identityAPI = apiAccessor.identityAPI

List users

offset = 0

// For each user
while (((users = identityAPI.getUsers(offset, increment, UserCriterion.USER_NAME_ASC)).size()) > 0) {

for(User user : users) {

	// If user doesn't already have an associated VacationAvailable object
	if(alreadyKnownEmployeeId.contains(user.id) == false) {
		// Create the object and set the default counter value

		DemandesConges va = new DemandesConges()
		va.bonitaBPMId = user.id
		va.solde = daysAvailableInitialValue
		newDemandesConges.add(va)
	}
}

offset += increment

}
I hope my question is understandable, i’m a little confused.

The most important thing when building BDM’s is to make sure you’ve got it right, right from the start and there will always be thousands of ways to do it.

That being said the way i would look at your issue is

I have an employee, and I have leave.

The employee data is essentially reference data and NOT transactional data, this is the leave.

So I would create my employee BDM as follows (or something that suits the actual design methodology you are using):

persistanceid empId name leaveAnnualAllowed (some people will get 30 days some people (management :) will get 90 or 120 days) leaveCurrentBalance

and my leave requests

persistanceid leaveId empId dateStart dateEnd noOfDays //remember weekends etc. so start Thursday come back Tuesday is not 5 days but only 3 days...

I would then simply do the following in code when a leave request is approved:

get employeeId record
leaveCurrentBalance = leaveAnnualAllowed - sum(noOfDays)

This way it becomes reference data for all your forms for the person in question - but only updated when approved by management.

Do not store the available days in the leave records as it means nothing to the leave request - only to the employee.

As I said at the beginning - the design of your data structures is paramount. You may want to look at this again.

regards
Seán

PS: As this reply offers an answer your question, and if you like it, please Mark UP and/or as Resolved.

Do you store Available Days anywhere? Just use this.

@Sean McP I store it in business data model

image

image