Two questions about overriding link queries by custom script

Hi all,
I’m trying to customize my Stock Entry form following this guide and face some difficulties as I feel more comfortable with back-end python than front-end JS… Thanks in advance for your help.

My relevant fields from Stock Entry Details look like this:

And my code:

frappe.ui.form.on('Stock Entry Detail', {
    card_atomic_name: function(frm, cdt, cdn) {
        // Get the child item
        let child = locals[cdt][cdn];

        // Set the custom query for the Card Atomic Name field in the child table
        frm.set_query('card_atomic_name', 'items', function() {
            return {
                filters: {
                    "has_variants": 1

        // Fetch the card_set_printings field from the selected item
        frappe.db.get_value("Item", child.card_atomic_name, "card_set_printings")
            .then(function(r) {
                let card_set_printings = r.message.card_set_printings;
                let sets = card_set_printings.split(', ');

                console.log('card_set_printings:', card_set_printings);
                console.log('sets:', sets);

                if (sets.length === 1) {
                    // If there is only one set, set the card_set field automatically
                    frappe.model.set_value(cdt, cdn, 'card_set', sets[0]);
                } else {
                    // If there are multiple sets, limit the search results to the sets in card_set_printings
                    frm.set_query('card_set', 'items', function() {
                        return {
                            filters: [
                                ['Item Attribute Value', 'abbr', 'in', sets]

Two questions:

  1. Filtering works for card_atomic_name, but not for card_set. Any ideas why? Logging functions show that this is not the case of wrong formatting: “sets” represent “abbr”.
  2. Search results are confusing as they show item names, e.g.:
    Is there any way to customize that? For example, to show field “abbr” instead.