Making sure no unique user is added twice to LearNow (rapid course) app

1
Hi all, after finishing my rapid developer course. I wanted to mess around with the LearnNow app a bit and try to improve some things on it. One bug that I found was that trainee's can be added to a trianing event twice, so I wanted to add a unique check to make sure they get a message and are thrown out when they try to add someone who is already in. I added some logic to ACT_Registration_Save workflow to make sure I am looking at the right objects: So step 1 is check if the name in the form is empty or not. Then I retrieve the trainee that has been selected and I retrieve the list of trainees already in this trianing event.    Now I want to build a check to see if the trainee is already in the the trianing event and throw an error if that's the case, but how do I make this check? preferably on the object ID since the name could (theoretically) be the same.    I tried to use a list operator but I couldn't get it working the way I wanted it too.    Please let me know if more information is needed! thank you for reading my question :).  
asked
1 answers
3

There are several ways to do this, but one of the easier ways would be to use an "intersect" list operation. The result of this list operation between your Traineelist and your $Trainee will be empty if none of the elements in either list (where the second is a list of 1 object) are equal to one another. If $Trainee is present in both, the list should return $Trainee and you can do an empty check on that.

 

Alternatively, which is the cleaner but slightly more difficult to write solution, you could do a straight retrieve from database where you retrieve over the same association as now, but you also check if "id = $Trainee". That should only return the same object if it exists over that association. You can then either do a count on this list and check if the count is equal to zero (the most performance-friendly way) or you can set the retrieve range to "first" and do an empty check.

 

image.png

answered