Submit doc programmatically

Is it possible to submit a doc programmatically? Or can we just save?

I have doc “health visit” and doc “student log”
Once a health visit is submitted I want it to create automatically and submit a student log based on a few fields from health visit.

?Here is what I have. I does create a doc and save it but do not submit it. Hence my question … is it possible at all?

def on_submit(self): 
	self.create_student_log() 
	
def create_student_log(self): 
	student = frappe.db.get_value("Student Patient", self.student_patient,  "student")
	term = frappe.get_single("Education Settings").get("current_academic_term")
	log_en = frappe.get_doc({ 
		"doctype": "Student Log", 
		"student": student,  
		"academic_term": term, 
		"date": self.date, 
		"log_type": "Medical", 
		"author_name": frappe.session.user, #This need to be changed to employee full name.
		"log": " ".join(filter(None,["Today between,", self.time_of_arrival, "and", self.time_of_discharge, "the above student visit the health office. Reason: ", self.note]))
	})
	log_en.save()
	log_en.submit()

Thanks for any hints / help.

You can add "docstatus": 1 in Student Log dictionary

2 Likes

Thanks @RWEMA_Aimable

That worked :wink: Why didn’t I think of that? Thank you so very much!!!