I am trying to automatically create Interview Feedback records once an Interview record is created. I have seen topics on the subject but the difference is that I would like to create the Interview Feedback records based on the Interviewers child table as shown below:
create a custom app.
in the hooks.py, add a doc_events hook for the interview record. probably better on “submit” than on create…
add a custom method in you app that is called from the hook where the feedback docs are created.
while thinking it through: you probably could also handle it as a front end JS script… gut feeling still says python backend.
This is a somewhat tricky exercise. The problem is that a Child Document’s controller methods are never triggered automatically by the Frappe framework.1
So. If you want to automatically create one child Interview Feedback for each child Interviewer, you have to perform some additional work:
On the -parent- Document, you must modify a controller method. You have several options. My advice would be using 'before_validate’. Why do I recommend this?
First, because ‘before_validate’ is called both when a Parent inserts, but also when a Parent updates. This is helpful. You only need to make one modification.
If you create a new Parent document with new Interviewers, your code will run.
If you add “Interviewers” to an existing Parent document, your code will run.
Second, ‘before_validate’ is called prior to ‘validate’. So you’ll be adding new data to your document -before- validation happens. This is a good thing. You wouldn’t want to insert data that isn’t examined and validated.
In your “before_validate”, you must detect whether the Interviewer row is new, or not. You can achieve that with something like this:
for each_row in self.get("interviewer"):
if each_row.get("__islocal"): # if true, then the child row is New
print("Add your code here, to append a new 'Interviewer Feedback' to the parent.")
pass # do nothing, because the Interviewer is not new.
Hopefully this helps. As Moe and Türker mentioned, you can patch the code using “hooks.py”, a Server Script, or a few other ways.
1Note: There actually is one exception: child controllers are called if you call their APIs with an external REST client. But that’s not important in this thread.)
Thank you Bran and Moe,
However, I am very new to programming and Frappe. I would have to do a lot of reading and practicing before I could implement these ideas. I thought the solution existed somewhere and I would just contextualize the code for my use
I have been reading up on and working with ERPNext and I think I want to tackle this now. I have however simplified it. I no longer want to create an interview feedback per the number of interviewers on the child table. Instead, I have designated only one interviewer to give the feedback using the field “main_interviewer”. I have also created a Server Script on the Interview doctype (on After Save) but it is throwing an error
I think the problem may be coming from doc.name on the interview doctype. On Interview Feedback, there is a mandatory link field to interview. I do not know if doc.name is the best way to pass that field to the interview feedback doctype