When I use a server-side script, I get many errors related to import statements. Even after removing the import statements, the errors still appear, and I cannot submit the form. When I add test data through the console, errors also show up.Cell In[9], line 11
1 doc = frappe.get_doc({
2 “doctype”: “Job Applicant”,
3 “email_id”: “applicant@example.com”,
(…)
8 “resume_attachment”: “”
9 })
—> 11 doc.insert(ignore_permissions=True, ignore_mandatory=True)
12 frappe.db.commit()
13 print(f"Inserted Job Applicant: {doc.name}")
File ~/frappe-desk-bench/apps/frappe/frappe/model/document.py:309, in Document.insert(self, ignore_permissions, ignore_links, ignore_if_duplicate, ignore_mandatory, set_name, set_child_names)
306 self.validate_higher_perm_levels()
308 self.flags.in_insert = True
→ 309 self.run_before_save_methods()
310 self._validate()
311 self.set_docstatus()
File ~/frappe-desk-bench/apps/frappe/frappe/model/document.py:1136, in Document.run_before_save_methods(self)
1133 return
1135 if self._action == “save”:
→ 1136 self.run_method(“validate”)
1137 self.run_method(“before_save”)
1138 elif self._action == “submit”:
File ~/frappe-desk-bench/apps/frappe/frappe/model/document.py:1011, in Document.run_method(self, method, *args, **kwargs)
1009 self.run_notifications(method)
1010 run_webhooks(self, method)
→ 1011 run_server_script_for_doc_event(self, method)
1013 return out
File ~/frappe-desk-bench/apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:42, in run_server_script_for_doc_event(doc, event)
39 if scripts:
40 # run all scripts for this doctype + event
41 for script_name in scripts:
—> 42 frappe.get_doc(“Server Script”, script_name).execute_doc(doc)
File ~/frappe-desk-bench/apps/frappe/frappe/core/doctype/server_script/server_script.py:169, in ServerScript.execute_doc(self, doc)
163 def execute_doc(self, doc: Document):
164 “”“Specific to Document Event triggered Server Scripts
165
166 Args:
167 doc (Document): Executes script with for a certain document’s events
168 “””
→ 169 safe_exec(
170 self.script,
171 _locals={“doc”: doc},
172 restrict_commit_rollback=True,
173 script_filename=self.name,
174 )
File ~/frappe-desk-bench/apps/frappe/frappe/utils/safe_exec.py:114, in safe_exec(script, _globals, _locals, restrict_commit_rollback, script_filename)
110 filename += f": {frappe.scrub(script_filename)}"
112 with safe_exec_flags(), patched_qb():
113 # execute script compiled by RestrictedPython
→ 114 exec(
115 compile_restricted(script, filename=filename, policy=FrappeTransformer),
116 exec_globals,
117 _locals,
118 )
120 return exec_globals, _locals
File : job_application:1
ImportError: import not found
In [10]:
I am creating a Job Application web form where user-submitted data is stored in the Job Applicant list. However, I am facing an issue: the backend before_insert
script is supposed to update existing records older than 6 months based on email and phone number, but it is generating duplicate entries.
When I use the API method submit_or_update_job_applicant
, it does not find the existing record; it does not update the record but creates a new record with updated data. This causes emails to be stored like this: tester8@example.com-2
.