Open an already added student batch

Hi,

I have a list of in student batch

like this

when i click a button i want to open student batch App Builder-abcd-2017-18

and i fill child table with values that i give

can any one please help me to understand how can i do this

You can write your script in the “onload” and can fill the child table with the value you give. You can check below file for more reference. (This is server side, you can also do the same client-side)

https://github.com/frappe/erpnext/blob/develop/erpnext/schools/doctype/guardian/guardian.py

@ManasSolanki okey but how can i open an existing student batch

I am using this code for opening student batch App Builder-TEST BATCH-2015-16

frappe.model.with_doctype("Student Batch", function() {
	var tlb = frappe.model.get_new_doc("Student Batch");
	$.each(stud_id, function(i, d) {
		var detail = frappe.model.get_new_doc("Student Batch Student", tlb,
		     "students");

		$.extend(detail, {
			"student": d,
			"student_name": stud_name[i],
			});
		})
	frappe.set_route("Form", "Student Batch/App Builder-TEST BATCH-2015-16", tlb.name);
	})

but i get error

this is what in url

http://localhost:8003/desk#Form/Student%20Batch%2FApp%20Builder-TEST%20BATCH-2015-16/New%20Student%20Batch%202

@ManasSolanki i can open student batch App Builder-TEST BATCH-2015-16

when i change code from above to

frappe.model.with_doctype("Student Batch", function() {
	var tlb = frappe.model.get_doc("App Builder-TEST BATCH-2015-16");
	$.each(stud_id, function(i, d) {
		var detail = frappe.model.get_new_doc("Student Batch Student", tlb,
		     "students");

		$.extend(detail, {
				"student": d,
				"student_name": stud_name[i],
			});
		})
		frappe.set_route("Form", "Student Batch/App Builder-TEST BATCH-2015-16");
	}) 

but chid table is not filling please help me to find what am i missing or where am i wrong

Hi @shahid_ecit,
How do you want to fill the child table? I mean when will you provide the values for child table. If you can explain your use case a bit, I can suggest something.

1 Like

@ManasSolanki i solved the problem only just now. I solved this problem by using frappe.call method $.each(stud_id, function(i, d) {
frappe.call({
method: “erpnext.schools.doctype.student_applicant.student_applicant.add_selected_student_to_childtable”,
args: {
stud_id:d,
stud_name:stud_name[i],
student_batch:“App Builder-abcd-2017-18”

},
callback:function(r){
	if(!r.exec){
		if(r.message)
		{	location.reload();
			frappe.set_route("Form", "Student Batch","App Builder-abcd-2017-18")
		}
	}
	}
 }) 

and whitelist function to of above call method is

@frappe.whitelist()
def add_selected_student_to_childtable(stud_id,stud_name,student_batch):
	doc = frappe.get_doc({
				"doctype": "Student Batch Student",
				"parent": student_batch,
				"parentfield":"students",
				"parenttype":"Student Batch",
				"student_name":stud_name,
				"student": stud_id

		})
	if(doc.insert()):
		return 'success'
1 Like