Custom Script Fetch Value From Master

I’m trying to fetch a value from Item into the Sales Order Item. According to this help topic:

https://erpnext.com/user-guide/customize-erpnext/custom-scripts/custom-script-examples/custom-script-fetch-values-from-master

I just need to setup a custom script on the Doc Type Sales Order Item of:

add_fetch(link_fieldname, source_fieldname, target_fieldname)

So in my example it’s

cur_frm.add_fetch('item_code','soi_size','soi_size')

But that doesn’t work - my Checkbox field for SOI Size does not get fetched into the Sales Order Item.

In fact if I replicate EXACTLY the example from that help topic above it still doesn’t work.

Has something changed since that custom script example was created?

1 Like

Hi,

Please ensure Field Type for both source and target field is same, and then
try.

Hi @umair

I have them both set to Check in my Item_code example but I tried exactly as described here https://erpnext.com/user-guide/customize-erpnext/custom-scripts/custom-script-examples/custom-script-fetch-values-from-master

and had both field types as Data and it still didn’t work.

It seems as if this feature either no longer works or the logic in the example is incorrect.

Only for document

cur_frm.cscript.custom_item_code = function(doc, cdt, cdn){
    var child = locals[cdt][cdn];
    cur_frm.call({
        "method": "frappe.client.get_value",
        "args": {
            "doctype": "Item",
            "filters": {
                "name":  child.item_code
            }
        },
        "child": child,
        "fieldname": "soi_size"
    })
}

Solved fetching the value from the server because add_fetch dont work for fields in grid

2 Likes

@max_morais_dmm

The new client script api is better because it allows you to attach multiple handlers

frappe.ui.form.on("Quotation", "item_code", function(frm) { .. });
2 Likes

@rmehta Thanks, I’ll start using it!

@rmehta @max_morais_dmm thanks to you both, very handy information!

is there any documentation for the client script api ?

Hello @monojoker, were you able to do it finally? I am struggling with the same thing as well. Any help will be appreciated.

@ahmed In monojoker’s case, I think the problem was that he made the script under ‘Sales Order Item’ instead of ‘Sales Order’. Child table scripts need to be in the parent’s file.

2 Likes

Thank you. This drove me nuts :wink:

Hi Max_morais_dmm

How to fetch the value of city from address doc to customer doct.in customer doc i have created on custom filed that is city…

Have you tried to wrote address.city in fetch from section of field city

1 Like

Use this
item_code.name of the field

1 Like