How to create a new record of a doctype using server side script

give example for creating a new record of a doctype using server side script

Hi @Vinay1 :

doc = frappe.get_doc(
		{
			"doctype": "ToDo",
			"color": "#761ACB",
			"description": "Hey Elvis!"
		})

doc.insert()

Lot of information here :slight_smile:
https://frappeframework.com/docs/user/en/desk/scripting/server-script

And here:

Hope this helps.

1 Like

thanks @avc for the solution
but i already have an idea regarding server side scripting, now i made a web form and when the web form is submitted then a new user should be created and the code for creating new user should be in the server side. this is what i am working on right now do you know how can we create a new user using server side script

@Vinay1 if you wonna create web form to create new user , then you don’t need to write any codes , the user will be created automatically using the form

hi @bahaou thanks
but i created a new doctype and a web form when a user submits the webform then a new record is being created for that doctype along with that a new user in User doctype should be created so regarding creating a new user i need server side code

Hi @Vinay1:

Your webform stores data on the new doctype. Use an event like after_insert of your new docytype to trigger the user creation method.

doc = frappe.get_doc(
		{
			"doctype": "User",
			"first_name": "Elvis",
			"email": "test@test.com",
			
		})

doc.append_roles("Blogger")
doc.insert()