Updated version of loaddoc with callback

I am trying to create a button in the projects module which is similar to the “Make Invoice” button that is found in a Sales Order screen. This will allow a user to create an invoice from a project task (assuming it is billable).

//Prepare the new Sales Invoice
var si = frappe.model.make_new_doc_and_get_name('Sales Invoice');
var table_row = locals[doctype][name];

si = locals['Sales Invoice'][si];

si.customer = frm.doc.customer;
si.project_name = frm.doc.name;

//Add the item to the Sales Invoice Items table
var d1 = frappe.model.add_child(si, 'Sales Invoice Item', 'items');

d1.item_name = table_row.title;

loaddoc('Sales Invoice', si.name);

I can get all the way up to creating a new Sales Invoice and populating the relevant fields (without having to save the document yet - which is very important for me). But after loading the Sales invoice and populating the customer field, I would like to run the “customer: function()” found in sales_invoice.js which will help to populate other fields such as territory, tax etc. automatically. Is there a version of loaddoc with callback or onload?

I noticed that loaddoc will accept an onload parameter but it does nothing. I’ve also confirmed this after looking at loaders.js.

loaddoc is deprecated

Try using route_options instead. These values get set after the doc is loaded.

frappe.route_options = { "customer": frm.doc.customer ... };
frappe.set_route("Form", "Sales Invoice", si.name);

PS: You seem to be an advanced user now. Please also spare a few minutes sometime in helping other users.

Yes this works! Thanks.

I would love to assist where possible. Have just subscribed to “Watching” in the Customisations category. I am also up for assignments if you happen to stumble on users whom have issues and if you think I can assist. Please send them across.

Great! We need more community leaders :smile:

Hi,

I’m facing a similar issue.

I used this piece of code in my custom script for Expense Claim:

frappe.set_route(‘Form’, ‘Journal Entry’, jv.name);

But, when I Make > Journal Entry,

I face this error on my console:

desk.min.js:15 Uncaught TypeError: callback is not a function

Thank you for any help!

Hi, i wanted to ask if there is a way to save the created doc instead of routing me to it


Best regards