I am writing a server script that creates a new lead doc using an AJAX call. I am using a web template to make the AJAX call. Unfortunately, my script is not working and is not producing any error messages. I am able to see a success request but it doesn’t create the new lead doc. Any help would be greatly appreciated.
I went ahead and revised my JS code to use frappe.call as suggested. However, I’m still encountering the same issue. It appears that the request is successful but, it is not creating a lead for some reason.
Not sure what I’m missing. In reference to the “path.to.module”, how do I determine the path? It seems like I’m able to make the call just fine with simply entering the name of the API Method. Unfortunately, I wasn’t able to find any documentation.
Thanks for all your help. I managed to figure it out. First, I need to clarify that this is a server script doc type. I am sending an AJAX request to the server script from the front end. The goal is to use the data that came with the request to create a new Lead. To do this I had to define the values accordingly using > frappe.form_dict
Here’s my revised server script:
first_name = frappe.form_dict.first_name
last_name = frappe.form_dict.last_name
email_id = frappe.form_dict.email_id
message = frappe.form_dict.message
# Create Lead document
lead = frappe.get_doc({
"doctype": "Lead",
"lead_name": f"{first_name} {last_name}",
"email_id": email_id,
"status": "Lead"
})
lead.insert(ignore_permissions=True)
# Create Communication if message exists
if message:
communication = frappe.get_doc({
"doctype": "Communication",
"communication_type": "Communication",
"subject": "Lead Inquiry Message",
"content": message,
"communication_medium": "Other",
"reference_doctype": "Lead",
"reference_name": lead.name
})
communication.insert(ignore_permissions=True)
frappe.db.commit()