Child Table set value of SELECT field once the Link Doctype choosen

Hi guys,

May i know how do i achieve something like set value of SELECT field when one of the link doctype field is alter/choose,

My code is like this :

frappe.ui.form.on("Item Group", {

item_group:function(frm, cdt, cdn){
var itemGroup = frappe.get_doc(cdt, cdn);
console.log("item group is  : " + itemGroup.item_group);
cur_frm.call({
    method:"booth_crm.booth_crm.doctype.promo_code.promo_code.getRelatedItems",
    args:{
        item_group:itemGroup.item_group,
    },
    callback:function(r){
        if(r.message==null){
            alert("Invalid in somewhere, please log out and log in again.");
        }
        else if(r.message!=null){
            console.log("items : " + JSON.stringify(r.message.ret.items));
            var items = JSON.stringify(r.message.ret.items);
            var itemsSize = JSON.parse(items).length;
            var itemShow = [];
            for(var i=0; i<itemsSize; i++){
                itemShow.push(JSON.stringify(r.message.ret.items[i].title).replace(/^"|"$/g,''));
            }
            frappe.meta.get_docfield("Item Group", "item_code", cur_frm.doc.name).options = ["hello", "bye"];
        }
    }    
})
}

});

What i want to achieve is , when go to doctype name as A , inside there is a table link to B doctype, this B got field as item_group, item_code(SELECT fieldtype), when i select item_group, it will send external service to get items return display in item_code (Select fieldtype). , i refer to some of the tutorial, i do not get how can i do it ~

Could anyone please help me?

1 Like

I got what i want from here…

this is the code:

cur_frm.cscript.operation_no = function(doc, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.parentfield=="bom_operations") erpnext.bom.set_operation_no(doc);
}

erpnext.bom.set_operation_no = function(doc) {
var op_table = doc.bom_operations || [];
var operations = [];

for (var i=0, j=op_table.length; i<j; i++) {
	var op = op_table[i].operation_no;
	if (op && !inList(operations, op)) operations.push(op);
}

frappe.meta.get_docfield("BOM Item", "operation_no",
	cur_frm.docname).options = operations.join("\n");