0

Question on Trigger Script - automatically enrolling the students of a class when linking a course to the class

Hi everyone, 

New to Ninox, I want to put a very simple script that automatically registers the students from a class when a course is created in this class. 

I have 4 tables 

student (one field : student_name) (+ linked to class)

class (one field : class_name)

course (one fields : course_name) + linked to class

and an association table, named course_students (linking students to the course)

The idea is that when I create a course and link it to a class, I don't want to have to add each of the students manually.  I would like all the students from the class to be automatically added as course_students (triggered after update of the class link, when creating a course)

Struggling with the a and p syntax of Ninox, I haven't find a way to make this trigger work. I'd gladly look at your ideas. Thanks !!

P.

8 replies

null
    • Mconneen
    • 4 yrs ago
    • Reported - view

    @pierre.. 

    I am a bit confused.. if  you already have the association of student to to class.. I am not sure what student to course is getting you.. 

    Some time ago.. there is a thread on this forum that discussed this data model. 
    dataModel

     

    Basically .. There is a Class (I think this is your Course)... and there a a Class Roster (I think this is your Student to Class) .. and then there is a Class Session Attendance .. which is for each class session / meeting (like each Tuesday at 2:00 pm) .. who attended.. 

    All of that said..  You are correct.. In the trigger after update between Class and Course...  do a for loop over the Class.Student relationship and and create a row between Course and Student.. 

    • Pierre_Laniray
    • 4 yrs ago
    • Reported - view

    Hi,

    thanks for the answer. I need the Class.Student Relationship because the relation between Class and Course is not automatic. In some cases (those for which I want the trigger), each Student (Joseph, Amy) from the same Class (4A) will be enrolled in the Courses of this class (Mathematics). But some Courses (Latin) are optional and are selected by only a sample of these Students.

    I've found your loop on the Forum and used it to generate "attendance sheets", and it works.

    But I was unable to twist it to fit this new need, although it looks very similar !

    What I've done :

    let s :=this;
    for p in select student where class =s.class do
    let a := (create student_course);
    a.(course_name := s);
    a.(students :=p.students);
    end  

    But i have it wrong somewhere !

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @pierre.. DISCLAIMER.. I DID NOT TEST THIS.. 

    Let us assume you are positioned on the Class row ... you have the students linked... and you just linked the single course.  I think the loop would be something like the following: 

    let thisClass := this;
    for p in thisClass.Student do 
        let a := create student_course;
        a.course := thisClass.Course;
        a.students := p;
    end;

    Because you are referencing the Class Student relationship.. you do not need the select.. you can iterate over each row .. (at least if it is composit I know it works).. Then the "p" is the Student object.. so when you are assigning the student to the student_course association .. you can just reference p.. 

    • Pierre_Laniray
    • 4 yrs ago
    • Reported - view

    @mcconeen Thanks for the help ; I'm not able to make it work so far, but I won't let go !

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @pierre

    Please post a picture of your data model..   I think I am getting lost in how you are using the terms class and course. 

    For example, Class (4A) will have many students (Joe, Amy, etc).....  But will Joe and Amy have many classes? 

    A Course will have many students... and based on your association table.. a student may enroll in many courses. 

    Can a Course have many Classes ?  So can Math will have Class 4A and 4B? 

    Can a Class (4A) have many Courses ?? Math, Science, English etc???   

    So... all that aside.. and trying to follow the verbiage above.. I built a data model like the following..

    dataModel

    I put Joe and Amy in Class 4A... and Pierre in Class 4B..   

    class4a

    Rereading your above post.. It appears that you link FROM course TO class .. So I linked Course Math to Class 4A

    Course

    I have the following logic in the Course.Class trigger after update..

    courseToClass

    Then for students Amy and Pierre... I added them to Course Latin. 

    latin

    amy

    Is this close to what you are trying to accomplish? 

    • Pierre_Laniray
    • 4 yrs ago
    • Reported - view

    Yes, it's exactly that. After fiddling around and finally understanding how to create records, I came up with the same solution. Since you appear quite the expert, I must say I'm proud of myself :-)

    Thank you for your help and your efforts to understand the problem (you got it all correct : students are enrolled in one class ; in this class, there are multiple courses only related to this class ; when the course is non optional, all students from the class are automatically enrolled by the script in the course) 

    I have another question rising from other developments : 

    - imagine an optional course within a class. Hence the enrollment script does not work (i use a boolean field "Optional" true or false and an if statement in the script)

    - i need to manually add the students one by one by clicking on the + button, which is quite tedious, but that's not the problem I'm concerned with so far.

    - When I click on the + button within the Course, I get to choose from the list of all students within the Students table (in a couple of years, that would give us all the students, for all the years...). It would be more relevant to only have the students enrolled in the Class, since you need to be in the Class to be able to join the Course. Is there a way to filter the Students Table when clicking the + button to make a connection ?

    Thanks again.

    • University of Chichester
    • Justin_McFarland
    • 4 yrs ago
    • Reported - view

    Hello Pierre, I'm also new to Ninox. I teach Business Management and Event Management at the University of Chichester and I was wondering if there's a solution for the Optional Course - to get the selected students automatically enrolled. 

    Justin McFarland, Adjunct Professor

     

    https://www.chi.ac.uk/business-school/our-courses https://customwritingz.net

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Pierre and @Justin, 

    Without thinking too hard about it... Sounds like a good use of a "constraint" on the look up logic to show only those students within the class. 

Content aside

  • 4 yrs agoLast active
  • 8Replies
  • 3100Views