Triggering function on load of doctype list view

Hello World,

I’m trying to trigger a function on load of a doctype’s “list view”. I know about

frappe.ui.form.on("{DocType}", "onload", {function})

but that will not run on a doctype’s “list view”. It will run on the New {DocType} view.

I also know about

onload: function(listview) {

}

but that will also not run on a doctype’s “list view”. It will run on load of a doctype and it will run the functions in the “listview”.

What is the trigger for this event?

Here is the ToDo doctype’s list view:

Refer below link.

1 Like

Thanks @suyash for the reply.

That doesn’t solve my issue. This is just the same as I was talking about. It is “onload” of the “New {DocType}” view. It is adding new menu items to the list view page but it isn’t triggered when a user visits that page

could be same error as:

https://github.com/frappe/frappe/issues/3001

1 Like

@JoEz

Thanks for the help.

What I have isn’t really an error, it may be a feature request or maybe the feature already exists, I’m not sure. I don’t think your link helps me though.

Thanks anyway

Have you found a solution? ,
I also encountered a problem similar to yours

For list view operations you might create a file like doctypename_list.js under the respective doctype folder.

After that you can write a onload function inside this list file.

Ex.
12

3 Likes

thank you for your answer ,

but that still isn’t a solution.

onload only occurs when you press the F5 or Refresh button.

but when you open via the Search function it won’t work anymore

let’s just say it happens only once. whereas I want to run the script when I open the list

You can write a code on refresh function instead onload

Ex. refresh: function(frm){
}

it will works on Search function too

I tried it, the function didn’t work

frappe.listview_settings['Payment Entry'] = {
  refresh:function(frm){
            console.log("Running Function this");
       }
 
}

hey, remove ‘=’ from you code

hey guys

Is there any trigger when i select purchase order list check box. you can see in image

Facing Same issue…

In list view, refresh function not working

are you find sloloution ?

Please check this :

frappe.listview_settings['Communication'] = {
	add_fields: [
		"sent_or_received","recipients", "subject",
		"communication_medium", "communication_type",
		"sender", "seen", "reference_doctype", "reference_name",
		"has_attachment"
	],

	filters: [["status", "=", "Open"]],

	onload: function(list_view) {
		let method = "frappe.email.inbox.create_email_flag_queue"

		list_view.page.add_menu_item(__("Mark as Read"), function() {
			list_view.call_for_selected_items(method, { action: "Read" });
		});
		list_view.page.add_menu_item(__("Mark as Unread"), function() {
			list_view.call_for_selected_items(method, { action: "Unread" });
		});
	},

	primary_action: function() {
		new frappe.views.CommunicationComposer({ doc: {} });
	}
};

I’m trying to trigger a function on load of a doctype’s “list view”, but in the listview for the doctype :

onload: function(listview) {
location.reload();
}

it applies to every existing document, meaning that it is not executed only once, but rather by the number of existing documents.

I want the code :

location.reload();

run only when I load the page of (list of doc)

What is the trigger for this event?

how can I get values of specific row