Logged in user name should be displayed automatically in a field of a particular doctype

I have a form with a field named FULLNAME and I need to display the user who is logging in by default and it should not be altered by the user.

How to do it? Can anyone give a solution to it.

Here’s how you can do it:

  1. Set the field as readonly in the form.
  2. Use JavaScript to set the value of the field to the fullname of the current user.
cur_frm.doc.fullname = frappe.user_info().fullname;

Alternatively, you can achieve the same using Python by utilizing any control methods such as before_insert. Here’s an example of how you can set the value in Python:

def before_insert(self):
    self.fullname = frappe.get_user().fullname

can you give me the full client script ?

Hi @SUKUMARAN_BV,

Please check it.

frappe.ui.form.on('Your DocType', {
	onload: function(frm) {
		frm.set_value('user_full_name_field_name', frappe.session.user_fullname);
	}
});

Please set your doctype and field name in script.

user_full_name_field_name = this is for doc type field name

frappe.session.user_fullname = This is for logged in user field name

Am i right ?

Yes !!

Should we write server script also for this to work?

It’s client script, not a server script.

Thank you