Documentation on virtual docfields


What’s the right way to create a virtual docfield with the Options field?

The documentation
bullet two says

Using the DocField.options
frappe.utils.now_datetime() - self.creation

The above mentioned Person.full_name example uses Python's f-string feature to achive this in a similar way.

The example uses self to refer to the document
Just above it there is a screenshot which reads f"{doc.first_name}" so it uses doc instead of self
When saving a doctype with a virtual field with either doc or self, Frappe says {self.first_name} is not a valid fieldname pattern. It should be {field_name}.
And in the end Frappe still tries to read the field from the database, saying pymysql.err.OperationalError: (1054, "Unknown column '....full_name' in 'field list'")


Use this syntax …

f'{doc.field1} - {doc.field2}'

It’s working. (Note that you can’t use this field on listview and many other situations)

Maybe screenshot is in the wrong place at document.

Hope this helps.

This is a message I get from Frappe while saving a doctype with such field:

@avc thanks1
doc.* works, as well as self.*, unless you try using the field as title, in which case it expects {fieldname} notation.

1 Like

To piggyback, I am having an issue calling a Server Script made from Desk, inside DocField.Options.

Script: frappe.flags.rating = 69
Options: run_script(‘calc_avg_rating’).get(‘rating’)

Screen Shot 2023-10-02 at 23.54.14


The Error I get when attempting to access the document(parent). The document is a child doctype.
Screen Shot 2023-10-02 at 23.57.16