I have added a client script for get items from one doctype to another,
But half of the code is successfully working
such as
1.Custom btn
2.Multi Dialog box when cstm button get clicked
After we select one from the multi dialog box the values are not binding
frappe.ui.form.on('Sales Invoice', {
refresh: function(frm) {
frm.add_custom_button(__('Issue'), function(){
new frappe.ui.form.MultiSelectDialog({
doctype: "Issue",
target: frm,
setters: {
},
get_query() {
return {
filters: { status: 'Closed' }
}
},
action(selections) {
if (selections && selections.length > 0) {
$.each(selections, function (i,custom_item) {
frm.add_child("customer",{customer:custom_item});
frm.add_child("items", {
items:custom_item
});
console.log(custom_item);
});
frm.refresh_field("items");
$(".modal").modal("hide");
}
}
});
}, __("Get Items From"));
}
});
Can you share gif/video? and also describe what you want to achieve?
After i click the get items in multi dialog box there will be a new row inserted but nothing get filled i want to fill what items i selected in issue
@amal_31845
console.log(custom_item); show this print in console
It show the id of issue doctype which is selected
This is not an item code no? Its an issue document name. thats why its not added in the item link field
i want to get the item table from issue to sales invoice so how can i get the document which i selected
$.each(selections, function (i,custom_item) {
frappe.db.get_all('Child Table Name', {
fields: ['item_code'],
filters: {
parent: ['in', [custom_item]]
}
}).then(records => {
console.log(records);
frm.add_child("items", {
item_code: records.item_code
});
frm.refresh_field("items");
})
}
if get_all not worked then try with get_list
Add child table name instead of ‘Child Table Name’
1 Like
for a normal field like customer how can i insert from issue to sales invoice
you can use frm.set_value('customer', CustomerID)
For now just add customer manually and try if the dialog box is working
2sales_invoice__custom_js:61 Uncaught TypeError: frappe.db.get_all is not a function
at String.eval (sales_invoice__custom_js:61:20)
at Function.each (jquery.js:383:19)
at frappe.ui.form.MultiSelectDialog.action (sales_invoice__custom_js:60:26)
at frappe.ui.Dialog.primary_action (multi_select_dialog.js:95:10)
at HTMLButtonElement. (dialog.js:192:20)
at HTMLButtonElement.dispatch (jquery.js:5135:27)
at Rt.handle (jquery.js:4939:28)
frappe.ui.form.on('Sales Invoice', {
refresh: function(frm) {
frm.add_custom_button(__('Issue'), function(){
new frappe.ui.form.MultiSelectDialog({
doctype: "Issue",
target: frm,
setters: {},
get_query() {
return {
filters: { status: 'Closed' }
}
},
action(selections) {
if (selections && selections.length > 0) {
$.each(selections, function (i,custom_item) {
frappe.db.get_all('custom_item', {
fields: ['item_code'],
filters: {
parent: ['in', [custom_item]]
}
}).then(records => {
console.log(records);
frm.add_child("items", {
item_code: records.itemss
});
frm.refresh_field("items");
})
});
$(".modal").modal("hide");
}
}
});
}, __("Get Items From"));
}
});
custom_item is the table name in issue
items is the table name in sales invoice
item_code is the field name in sales invoice
itemss is the item code field name in issue
“custom_item is the table name in issue”
is it table field name or Table name?
“itemss is the item code field name in issue”
ok then you can change this line to the correct field name of item code
fields: ['item_code'],
field name not table name table name is issue items
itemss is the field in issue which corresponding to item code
frappe.db.get_all(**'custom_item'**, {
Add the table name here. Add the same name in there
if (selections && selections.length > 0) {
$.each(selections, function (i,custom_item) {
frappe.db.get_all('Issue items', {
fields: ['itemss'],
filters: {
parent: ['in', [custom_item]]
}
}).then(records => {
console.log(records);
frm.add_child("items",{
item_code: records.itemss
});
frm.refresh_field("items");
})
});
$(".modal").modal("hide");
}
i have tried both
frappe.db.get_all(‘Issue items’, {
frappe.db.get_all(‘custom_item’, {
both shows frappe .get all is not a function
try with get_list
frappe.db.get_list('Issue items', {
action(selections) {
if (selections && selections.length > 0) {
$.each(selections, function (i,custom_item) {
frappe.db.get_list('Issue Items', {
fields: ['itemss'],
filters: {
parent: ['in', [custom_item]]
}
}).then(records => {
console.log(records);
frm.add_child("items",{
item_code: records.itemss
});
frm.refresh_field("items");
})
});
$(".modal").modal("hide");
}
}
now
showing lilke this
What should i add here the field name of issue items or the name - issue items parent: [‘in’, [custom_item]]
@Safvan_Ph
Because you need the Items from the selected issue docs ight?
Console showing an empty array. can you check if there is items in the selected Issue doc