When i am setting filter using this so it is working
frappe.listview_settings[‘Sales Invoice’] = {
onload : function(listview) {
console.log(frappe.session.user)
frappe.route_options = {
“affiliate_code”: “promo_1PvLuqBcU7b1vexSZxnJIyHf”
};
listview.refresh();
}
};
But when I am fetching value then use it to set filter so it is not working
frappe.listview_settings[‘Sales Invoice’] = {
refresh: function(listview) {
// Fetch the custom_coupon_code of the logged-in user
frappe.db.get_value(‘Employee’, {‘prefered_email’: frappe.session.user}, ‘custom_coupon_code’)
.then(r => {
let values = r.message;
const logged_user_code = values.custom_coupon_code;
console.log(logged_user_code)
// Set route options to filter the list view
frappe.route_options = {
"affiliate_code":logged_user_code
};
// Refresh the list view to apply the filter
listview.refresh();
})
.catch(error => {
console.error("Error fetching custom_coupon_code:", error);
});
}
};