How to Filter Asset by user’s location in the in Asset Movement Doctype, child doctype name is Asset Movement Item, table name is assets
Thanks and Regards
Shubham
How to Filter Asset by user’s location in the in Asset Movement Doctype, child doctype name is Asset Movement Item, table name is assets
Thanks and Regards
Shubham
You should check the documentation of the Overriding Link Query By Custom Script and apply the script according to the scenario.
Reference Example:
I hope this helps.
Thank You!
frm.set_query("asset", "assets", () => {
const filters = {
status: ["not in", ["Draft"]]
};
if (frm.doc.purpose === 'Issue') {
filters.custodian = "";
} else if (frm.doc.purpose === 'Receipt') {
filters.custodian = ['!=', ''];
} else if (frm.doc.purpose === 'Transfer') {
if (frm.doc.transfer_to === 'Location to Location' || frm.doc.transfer_to === 'Location (Store) to Desk') {
filters.custodian = '';
filters.asset_status = 'In Stock';
} else if (frm.doc.transfer_to === 'Desk to Location (Store)') {
filters.user_type = 'Not User';
filters.asset_status = 'Allocated';
}
}
// Check if doc.purpose has a value
if (frm.doc.purpose) {
// Get the current user's location from the user's doctype
const currentUser = frappe.session.user;
frappe.db.get_list('User', {
filters: {
name: currentUser
},
fields: ['location'],
limit: 1
}).then((results) => {
if (results && results.length > 0) {
const currentUserLocation = results[0].location;
// Filter assets by location
filters.location = currentUserLocation;
}
});
}
return { filters };
})
Actually, this code is showing filter Location by User’s location, like this,
Location = Bengaluru, Where, Bengaluru is location of frappe.session.user
but actually asset is not filtering by session user’s location, and rest filter is working
can you please help me?
@NCP
Thanks and Regards
Shubh