Error with custom virtual docfield in list view

I have added a custom docfield, type “Data”, to the Sales Order doctype. I have checked “Is Virtual”, “In List View” and “Read Only” (just in case it is required). In the “Options” field, I have put a simple line of code: “frappe.utils.now_datetime() - self.creation”
This is the code used in the documentation example.

When I navigate to the Sales Order List View, I get the error: ‘pymysql.err.OperationalError: (1054, “Unknown column ‘tabSales Order.carrier’ in ‘field list’”)’

I have tried the other documented method of extending the SalesOrder class through hooks.py but I get the same result.

Is a virtual field expected to be visible in the List View?

Hi, due to the way list views work, virtual field just won’t work there. It needs document object.

We should be hiding this option to avoid the error. Can you open an issue on Framework repository?

Thank you very much for your quick answer. I understand. I’ll open an issue concerning the “In List View” option on the virtual docfield.

Meanwhile, is there a way I can place a column of computed values in the List View? Perhaps by adding some code in my custom app?

You can customize listview, adding or modifying data using formatters … take a look here:
https://frappeframework.com/docs/v14/user/en/api/list

Hope this helps.

Thank you, avc!
I’ve already customised the list view indicator and added a button. I had completely missed the formatters. I think that should work for what I want to do. I should have asked my second question in a separate post because now I cannot mark your answer as the solution when ankush provided the solution to the original question.

1 Like

Don’t worry. I’m happy if you can solve! :wink: