Hi
I want to implement a conditional create listener that triggers when a related object (of the main object) met a condition.
I have this table called DBSolicitudes.
And I have this code to create a BDSolicitudes object:
static func RequestAddDTMTeam( RecID_DTM: String, equipo: String, completion: @escaping (Result< Bool, Error>) -> ()){
let request = BDSolicitudes()
Backendless.shared.data.of(BDSolicitudes.self).save(entity: request,
responseHandler: { result in
let solicitud = result as! BDSolicitudes
let dataStore2 = Backendless.shared.data.of(BDSolicitudes.self)
dataStore2.setRelation(columnName: "Usuario", parentObjectId: solicitud.objectId!, childrenObjectIds: [RecID_DTM], responseHandler: { relations in
dataStore2.setRelation(columnName: "Equipo", parentObjectId: solicitud.objectId!, childrenObjectIds: [equipo], responseHandler: { relations in
completion(.success(true))
}, errorHandler: {fault in
completion(.failure(fault))})
}, errorHandler: {fault in
completion(.failure(fault))})
}, errorHandler: {fault in
completion(.failure(fault))})
}
On the other hand, I have the following code so, the user related to the BDSolicitudes object can process the request.
func configurarsubscripciones(usuId: String) {
let eventHandler = Backendless.shared.data.of(BDSolicitudes.self).rt
let cuando = "Usuario.objectId = '\(usuId)' "
_ = eventHandler?.addCreateListener(whereClause: cuando, responseHandler: { createdObject in
let sol = createdObject as! BDSolicitudes
print(NSLocalizedString("You have bee requested to join a new team", comment: ""))
print ("cambio en la tabla solicitudes")
FuncionesBackendless.BuscaEquipoID (ID_Equipo: sol.Equipo!.objectId!) {resultados in
switch (resultados){
case .success(let equipo):
DispatchQueue.main.async {
self.equipoActivo = MVDTM (NuevoEquipo: equipo, esSM: false, esReal: true)
self.SelMenEqu = .Miembros
self.hayAlerta = .Invitacion}
case .failure(let error):
print (error.localizedDescription)
}
}
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})}
My problem is that the listener is not triggered. The reason should be that the User relation has not been set yet at the moment of the object creation.
I tried as well using addUpdateListener but (I don’t know why), but It is not triggered.
If I use an Unconditional Delivery Listeners, it does work, so think it is not an issue with the listener setup.
Does anyone an idea on how to manage this?
Thank you for your help in advance.