Data Inserting issues

Hi,

bulk.py
from future import unicode_literals
import datetime

from frappe import _
import frappe
import frappe.database
import frappe.utils
import frappe.utils.user

@frappe.whitelist()
def bulkdatasave():
for x in range(1):
a = frappe.get_doc({
“doctype”:“Bulk Data”,
“first_name”:“firstname” + str(x),
email":"test@gmail.com” + str(x),
“address”:“test address” + str(x),
“phone”:“test_phone” + str(x)
})
if a.insert(ignore_permissions=True):
frappe.msgprint(a.name)
frappe.msgprint(“Inserted”)
else:
frappe.msgprint(“Not inserted”)

Im using the following link to call the method

http://localhost/api/method/erpnext.bulk.bulkdatasave

Method called…
It showing Inserted but data is getting rolled back i think.
because no data is displaying in bulk doctype

Why not run ‘bench mysql’ then query that database table

select * from `tabBulk Data`;

Use backticks in the select!

Assuming the code is the source of your problem, someone else may be able to spot that.

When I’m trying to insert random data its not working in the way I have given above…

What’s the issue there, whether i need to use the query here?

No, a select query is simply one means to check that your insert succeeded.

You were not sure about that success, as you said this:

“It showing Inserted but data is getting rolled back i think.”

I can’t speak to your code here.

@frappe.whitelist()
def bulkdatasave():
	for x in range(4):
		a = frappe.get_doc({
					"doctype":"Bulk Data",
					"first_name":"firstname" + str(x),
					"email":"test@gmail.com" + str(x),
					"address":"test address" + str(x),
					"phone":"test_phone" + str(x)
				})
		if a.insert(ignore_permissions=True):
			frappe.msgprint(a.name)
			frappe.msgprint("Inserted")
		else:
			frappe.msgprint("Not inserted")

i littel bit change in your code

i am use post method to call this
POST http://0.0.0.0:8002/api/method/erpnext.api.bulkdatasave

1 Like