Hi there, If I have multiple documents linked to one document, how do I retrieve their IDs in an array to be used later in the script?
Please try it. I used the default “Link” concept to get all links. so check it.
It’s a sample script.
frappe.ui.form.on("Sales Order", {
refresh: function (frm) {
frm.add_custom_button("Get All Links", function () {
frappe.xcall("frappe.desk.form.linked_with.get", {
doctype: frm.doctype,
docname: frm.docname,
}).then((response) => {
let linked_ids = [];
Object.keys(response).forEach((doctype) => {
response[doctype].forEach((doc) => {
linked_ids.push(doc.name);
});
});
console.log("--------------", JSON.stringify(linked_ids));
frappe.msgprint({
title: __("Success"),
message: __("Linked document IDs have been stored in the custom field."),
indicator: "green",
});
});
});
},
});
Thanks for helping out. I tried using the script and it seems to be executing (but I am getting permissions error):
Is there a way to filter out the doctypes that are delivery notes?
I tried adding a filter to the this part of the code:
frappe.xcall("frappe.desk.form.linked_with.get",{
doctype:frm.doctype,
docname:frm.docname,
filters:{'doctype':'Delivery Note'}
No need to apply a filter, because it’s already applied in the below line.
But then I am getting the error shown above. I am using Frappe Cloud. How do I go about it?
It’s just sample code, now you have to add logic and set it according to the scenario. we just set the default link logic, nothing more.
I understand. However, when I am just starting with this first parameters:
frappe.ui.form.on('Sales Invoice', {
refresh(frm) {
frappe.xcall("frappe.desk.form.linked_with.get", {
doctype: frm.doctype,
docname: frm.docname,
});
The error already appears without adding any other code to the script:
I am confused why it appears. Any insight on it would be great, thanks!