Fetch student group doctype to another doctype

Hi All

I need to fetch the student group name into a customized doctype called By cat List into student_group filed as below :

I need the custome script

Thanks

I think you don’t even need a script… in your doctype, assuming your Student is a Link field with name student (linking to Student), then simply add in your student_group Data field as option “student.student_group” (when the linked student has a field student_group). You will have to add this link to the group to the student doctype. That’s all.

Hope this helps.

Many thanks for your prompet reply, Your solution is very close to my need,
the last thing is to fetch the student group with each assigned student.

The new field Student Group in Students shows all the student groups in the system not what has assigend …

Sorry, I am not sure if I understand correctly. You have added “student_group” to DocType “Student”. In the “Student” DocType, you will assign the group. Then, when assigning a student to a car (“Car” DocType), when you select the student, you would like to have the “student_group” to be fetched from the selected student to the “Car” DocType? Or should there be a change of the student record?

Yes exactly , choosing a student in a Car Doctype then the student group data appeared .
So I want Student Group field in Student Doctype fetches automatically the data from Student Group Doctype.

If the above direct assignment in the DocType does not resolve this, try this custom script (or as .js in your doctype):

frappe.ui.form.on("Car", "student", function(frm) {
   frappe.call({
        "method": "frappe.client.get",
        "args": {
               "doctype": "Student",
               "name": frm.doc.student
         },
         "callback": function(response) {
              var student = response.message;
              if (student) {
                   frm.set_value('student_group', student.student_group);
              }
          }
     });
 });

Hope this helps.