41
Views
3
Comments
Solved
Trying to apply Recursion to find out the Mentor of a student.
Application Type
Reactive
Service Studio Version
11.54.1 (Build 62118)

Hello Ousystems community,

I'm trying to implement a Client action using Recursion to find out the "Mentor" of a "Student" in a certain school. 

The problem is that a Mentor is a student and he can have a Mentor aswell. So MentorId primary key is StudentId.

My problem is that doing this way the MentorId will be Null in the end.

Can I add an aux variable to an Recursion Action in order to save the last MentorId? Like in second example.

Or should I add this variable to my screen and every time I click to find a new student it saves the last studentid before becoming Null.

I hope this post is clear enough, if not i'm sorry, it's my first post in this forum.

Thank you in advance!

example 1:

Example 2:


2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello Miguel.


One solution is to build a list with all those mentors.

Get the mentor of current StudentId.

If there is no mentor, just return empty.

If there is a mentor, Find Mentor's Mentor (it will return a list of mentors ordered)

Append this mentor to the Output (it will be the first entry) and then append the list of mentors.

Your output will be the full list of mentors.

This is recursive.

With this list, you can then find the last Id of anything else.

2016-04-22 00-29-45
Nuno Reis
 
MVP

If you only want the last, you can do it this way(smae logic, but only returns the last):

2023-08-08 09-00-45
Miguel Nunes

Thank you for you reply, it was very helpful ! 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.