Hello,
I need to get all checked items from the listview after performing some action from the action button from the client script.
Is this possible?
Thank you
-
Create a custom script for the doctype that you want to add the button to. You can do this by going to Custom Script List and clicking on New.
-
In the custom script, write a function that gets the checked items from the list view using
frappe.get_list_view().get_checked_items()
-
Write another function that performs the action that you want to do with the checked items. For example, if you want to update a field value for each checked item, you can use frappe.call to call a server-side method that does the update.
-
Add a button to the list view using
frappe.listview_settings['Doctype Name'].onload = function(listview) { listview.page.add_menu_item('Button Label', function() { // your code here }); }
Replace ‘Doctype Name’ with your doctype name and ‘Button Label’ with your button label. In the function, call the functions that you wrote in the previous steps.
- Save and reload the list view to see the button.
Here is an example of a client script that adds a button to the Payment Entry list view that updates the status of all checked items to ‘Paid’:
// get checked items from list view
function get_checked_items() {
return frappe.get_list_view().get_checked_items();
}
// update status of checked items to 'Paid'
function update_status(items) {
frappe.call({
method: 'custom_app.custom_app.doctype.payment_entry.payment_entry.update_status',
args: {
items: items
},
callback: function(r) {
if (r.message) {
frappe.msgprint(r.message);
}
frappe.get_list_view().refresh();
}
});
}
// add button to list view
frappe.listview_settings['Payment Entry'].onload = function(listview) {
listview.page.add_menu_item('Mark as Paid', function() {
var items = get_checked_items();
if (items.length > 0) {
update_status(items);
} else {
frappe.msgprint('Please select some items first.');
}
});
}
I hope this will help.
Thanks,
Thank you for the response,
In the above code, this is adding a custom button in the menu but my need is : from the action button the action is already present from the workflow action.
e.g. I created the workflow action “Approve”,
Here my need is I checked 5 items, and then from the action button I select Approve, As soon as I approve these items from the action button Get all checked items.