Show/Hide a Form Field if Record is Saved

Hello,

I am using the Form Builder, not scripting, to customise a form.
How can you set a form field to be either shown or hidden, depending on the status of the record: new vs saved?

I tried Eval:!(doc.__islocal) but that did not seem to work.

Is there any comprehensive guide on using the eval:doc option in the Depends On, Mandatory Depends On etc. Most I have found so far by searching this forum or going through individual fields in ERPNext to find examples.

Thanks,
Paul

in your field in customize form try eval: doc.docstatus == 0

2 Likes

This field is JS (JavaScript), but if it were python, could open a python CLI with:

bench console

which you can use to inspect any doc object. In that console, just get one of your doctype objects (a doc), for instance using:

frappe.get_list('YourDocType')

which should produce a list of names, then use one of them to get the doc object:

doc = frappe.get_doc('YourDocType', 'YourDocName')

then use python’s function

dir('YourPythonObject')

to inspect the properties and methods of your doc.

E.g. like this:

In [2]: frappe.get_list('Airplane')
Out[2]: 
[{'name': '15a73ad9e4'},
 {'name': 'e04a846d8b'},
 {'name': '27becc5188'},
 {'name': 'd541a8797a'},
 {'name': '352df66dcb'},
 {'name': '261708836d'},
 {'name': '90a1085023'},
 {'name': '0093fe33cd'},
 {'name': 'bab9a05797'},
 {'name': '84542ae2ff'},
 {'name': '086b085d42'},
 {'name': '130a7ab6f1'}]

In [3]: doc = frappe.get_doc({'doctype':'Airplane', "name": "261708836d"})

In [4]: doc
Out[4]: <Airplane: 261708836d>

In [5]: dir(doc)
Out[5]: 
['__annotations__',
 '__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_cancel',
 '_extract_images_from_text_editor',
 '_fix_numeric_types',
 '_fix_rating_value',
 '_get_missing_mandatory_fields',
 '_get_table_fields',
 '_init_child',
 '_rename',
 '_reserved_keywords',
 '_sanitize_content',
 '_save',
 '_save_passwords',
 '_set_defaults',
 '_submit',
 '_sync_autoname_field',
 '_table_fieldnames',
 '_validate',
 '_validate_code_fields',
 '_validate_constants',
 '_validate_data_fields',
 '_validate_length',
 '_validate_links',
 '_validate_mandatory',
 '_validate_non_negative',
 '_validate_selects',
 '_validate_update_after_submit',
 'add_comment',
 'add_seen',
 'add_tag',
 'add_viewed',
 'airline',
 'append',
 'apply_fieldlevel_read_permissions',
 'as_dict',
 'as_json',
 'cancel',
 'capacity',
 'cast',
 'check_docstatus_transition',
 'check_if_latest',
 'check_if_locked',
 'check_no_back_links_exist',
 'check_permission',
 'clear_cache',
 'copy_attachments_from_amended_from',
 'creation',
 'db_get',
 'db_insert',
 'db_set',
 'db_update',
 'db_update_all',
 'deferred_insert',
 'delete',
 'delete_key',
 'docstatus',
 'doctype',
 'dont_update_if_missing',
 'extend',
 'flags',
 'get',
 'get_all_children',
 'get_assigned_users',
 'get_db_value',
 'get_doc_before_save',
 'get_document_share_key',
 'get_field_name_by_key_name',
 'get_formatted',
 'get_invalid_links',
 'get_label_from_fieldname',
 'get_latest',
 'get_liked_by',
 'get_onload',
 'get_parentfield_of_doctype',
 'get_password',
 'get_permissions',
 'get_permlevel_access',
 'get_signature',
 'get_table_field_doctype',
 'get_tags',
 'get_title',
 'get_url',
 'get_valid_columns',
 'get_valid_dict',
 'get_value',
 'getone',
 'has_permission',
 'has_permlevel_access_to',
 'has_value_changed',
 'hook',
 'idx',
 'in_format_data',
 'init_child_tables',
 'init_valid_columns',
 'initial_audit_completed',
 'insert',
 'is_child_table_same',
 'is_dummy_password',
 'is_locked',
 'is_new',
 'is_print_hide',
 'is_whitelisted',
 'load_doc_before_save',
 'load_from_db',
 'lock',
 'log_error',
 'meta',
 'model',
 'modified',
 'modified_by',
 'name',
 'notify_update',
 'owner',
 'permitted_fieldnames',
 'precision',
 'queue_action',
 'raise_no_permission_to',
 'reload',
 'remove',
 'remove_tag',
 'remove_unpicklable_values',
 'rename',
 'reset_seen',
 'reset_values_if_no_permlevel_access',
 'round_floats_in',
 'run_before_save_methods',
 'run_method',
 'run_notifications',
 'run_post_save_methods',
 'run_trigger',
 'save',
 'save_version',
 'set',
 'set_docstatus',
 'set_fetch_from_value',
 'set_name_in_children',
 'set_new_name',
 'set_onload',
 'set_parent_in_children',
 'set_title_field',
 'set_user_and_timestamp',
 'show_unique_validation_message',
 'submit',
 'throw_length_exceeded_error',
 'unlock',
 'update',
 'update_child_table',
 'update_children',
 'update_if_missing',
 'update_modified',
 'update_single',
 'validate_from_to_dates',
 'validate_higher_perm_levels',
 'validate_set_only_once',
 'validate_table_has_rows',
 'validate_update_after_submit',
 'validate_value',
 'validate_workflow']

But you can also inspect your doctype:

In [6]: doc = frappe.get_doc({'doctype':'DocType', "name": 'Airplane'})

In [7]: doc
Out[7]: <DocType: Airplane>

In [8]: dir(doc)
Out[8]: 
['TYPE_CHECKING',
 '__annotations__',
 '__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_assign',
 '_cancel',
 '_comments',
 '_extract_images_from_text_editor',
 '_fix_numeric_types',
 '_fix_rating_value',
 '_get_missing_mandatory_fields',
 '_get_table_fields',
 '_init_child',
 '_last_update',
 '_liked_by',
 '_rename',
 '_reserved_keywords',
 '_sanitize_content',
 '_save',
 '_save_passwords',
 '_set_defaults',
 '_submit',
 '_sync_autoname_field',
 '_table_fieldnames',
 '_user_tags',
 '_validate',
 '_validate_code_fields',
 '_validate_constants',
 '_validate_data_fields',
 '_validate_length',
 '_validate_links',
 '_validate_mandatory',
 '_validate_non_negative',
 '_validate_selects',
 '_validate_update_after_submit',
 'actions',
 'add_child_table_fields',
 'add_comment',
 'add_nestedset_fields',
 'add_seen',
 'add_tag',
 'add_viewed',
 'after_delete',
 'after_rename',
 'allow_auto_repeat',
 'allow_copy',
 'allow_events_in_timeline',
 'allow_guest_to_view',
 'allow_import',
 'allow_rename',
 'app',
 'append',
 'apply_fieldlevel_read_permissions',
 'as_dict',
 'as_json',
 'autoname',
 'before_export',
 'before_reload',
 'before_rename',
 'beta',
 'cancel',
 'cast',
 'change_modified_of_parent',
 'check_developer_mode',
 'check_docstatus_transition',
 'check_if_latest',
 'check_if_locked',
 'check_indexing_for_dashboard_links',
 'check_no_back_links_exist',
 'check_permission',
 'clear_cache',
 'color',
 'colour',
 'copy_attachments_from_amended_from',
 'creation',
 'custom',
 'db_get',
 'db_insert',
 'db_set',
 'db_update',
 'db_update_all',
 'default_email_template',
 'default_print_format',
 'default_view',
 'deferred_insert',
 'delete',
 'delete_key',
 'description',
 'docstatus',
 'doctype',
 'document_type',
 'documentation',
 'dont_update_if_missing',
 'editable_grid',
 'email_append_to',
 'engine',
 'ensure_minimum_max_attachment_limit',
 'export_doc',
 'export_types_to_controller',
 'extend',
 'fields',
 'flags',
 'force_re_route_to_default_view',
 'get',
 'get_all_children',
 'get_assigned_users',
 'get_db_value',
 'get_doc_before_save',
 'get_document_share_key',
 'get_field_name_by_key_name',
 'get_formatted',
 'get_invalid_links',
 'get_label_from_fieldname',
 'get_latest',
 'get_liked_by',
 'get_max_idx',
 'get_onload',
 'get_parentfield_of_doctype',
 'get_password',
 'get_permissions',
 'get_permlevel_access',
 'get_signature',
 'get_table_field_doctype',
 'get_tags',
 'get_title',
 'get_url',
 'get_valid_columns',
 'get_valid_dict',
 'get_value',
 'getone',
 'has_permission',
 'has_permlevel_access_to',
 'has_value_changed',
 'has_web_view',
 'hide_toolbar',
 'hook',
 'icon',
 'idx',
 'image_field',
 'in_create',
 'in_format_data',
 'index_web_pages_for_search',
 'init_child_tables',
 'init_valid_columns',
 'insert',
 'is_calendar_and_gantt',
 'is_child_table_same',
 'is_dummy_password',
 'is_locked',
 'is_new',
 'is_print_hide',
 'is_published_field',
 'is_submittable',
 'is_tree',
 'is_virtual',
 'is_whitelisted',
 'issingle',
 'istable',
 'links',
 'load_doc_before_save',
 'load_from_db',
 'lock',
 'log_error',
 'make_amendable',
 'make_attachments_public',
 'make_controller_template',
 'make_repeatable',
 'max_attachments',
 'menu_index',
 'meta',
 'migration_hash',
 'modified',
 'modified_by',
 'module',
 'name',
 'naming_rule',
 'notify_update',
 'nsm_parent_field',
 'on_update',
 'owner',
 'parent_node',
 'permissions',
 'permitted_fieldnames',
 'precision',
 'prepare_for_import',
 'preserve_naming_series_options_in_property_setter',
 'print_outline',
 'queue_action',
 'queue_in_background',
 'quick_entry',
 'raise_no_permission_to',
 'read_only',
 'reload',
 'remove',
 'remove_tag',
 'remove_unpicklable_values',
 'rename',
 'rename_files_and_folders',
 'rename_inside_controller',
 'reset_seen',
 'reset_values_if_no_permlevel_access',
 'restrict_to_domain',
 'round_floats_in',
 'route',
 'run_before_save_methods',
 'run_method',
 'run_module_method',
 'run_notifications',
 'run_post_save_methods',
 'run_trigger',
 'save',
 'save_version',
 'scrub_field_names',
 'search_fields',
 'sender_field',
 'set',
 'set_base_class_for_controller',
 'set_default_in_list_view',
 'set_default_translatable',
 'set_defaults_for_autoincremented',
 'set_defaults_for_single_and_table',
 'set_docstatus',
 'set_fetch_from_value',
 'set_name_in_children',
 'set_new_name',
 'set_onload',
 'set_parent_in_children',
 'set_title_field',
 'set_user_and_timestamp',
 'setup_autoincrement_and_sequence',
 'setup_fields_to_fetch',
 'show_name_in_global_search',
 'show_preview_popup',
 'show_title_field_in_link',
 'show_unique_validation_message',
 'smallicon',
 'sort_field',
 'sort_order',
 'states',
 'subject',
 'subject_field',
 'submit',
 'sync_doctype_layouts',
 'sync_global_search',
 'tag_fields',
 'throw_length_exceeded_error',
 'timeline_field',
 'title_field',
 'track_changes',
 'track_seen',
 'track_views',
 'translated_doctype',
 'unlock',
 'update',
 'update_child_table',
 'update_children',
 'update_fields_to_fetch',
 'update_if_missing',
 'update_modified',
 'update_single',
 'validate',
 'validate_child_table',
 'validate_document_type',
 'validate_field_name_conflicts',
 'validate_from_to_dates',
 'validate_higher_perm_levels',
 'validate_name',
 'validate_nestedset',
 'validate_set_only_once',
 'validate_table_has_rows',
 'validate_update_after_submit',
 'validate_value',
 'validate_virtual_doctype_methods',
 'validate_website',
 'validate_workflow',
 'website_search_field']

You can do a similar thing using the javascript console of the browser to get the names (and the formatting) of the objects after they were transferred from the Python backend to the display machinery where the eval is executed to build the user interface.

1 Like

I just tried to explore the JS console for you to answer that question, but there is too much information for me at the moment to absorb in order to find my way around.

I’m on Firefox and Ctrl+Shift+K opens the JS console. So here you can explore.

If you just type “frappe” and then Ctrl+Enter, you get info about the frappe object.

If you type frappe.db.get_doc(‘YourDoctype’, ‘YourDoctypesName’) things become more interesting.

If you start typing, after the first letter you can chose which object to explore.

You can also try JS expressions.

But I’m not sure if the logic for the field evaluation runs in the browser or in the node server.
In fact, trying “frm” or “frm.doc” yields an error.
So maybe all the UI stuff is built in node? (Or still elsewhere?)
I’m not sure how to proceed.

Maybe try Client Script to inspect the objects you are searching.

If somebody (maybe @buildwithhussain?) could elucidate how to inspect these, please give some hints to get us on the way to explore/inspect (and debug) these.

Another way would be to grep a known variable in the apps/frappe directory and see what shows up, and take it from there.

1 Like

Thanks, will give that a try.

Thanks for looking in to this, looks like another way of finding lots of useful information.