[Newbie] Custom Script to check for Drop shipped items while creating Sales invoice

Expected bahaviour: When creating a sales invoice from a sales order with even one of the item which has to be drop shipped, a custom message has to be given. I was able to do so by inserting some code within the sales_order.js file.

			method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
			frm: this.frm
		var flag = 0;
		for (var i in this.frm.doc.items) {
			var item = this.frm.doc.items[i];
			if(item.delivered_by_supplier === 1){
				flag = 1;
		if(flag ===1){
			frappe.msgprint("First create Purchase Order and Purchase Invoice");

Now whenever I click on “make invoice”, it checks all the items and gives a message if even one of the item has to be drop shipped:


I want to do the same, but with a custom script, without touching the core files. Since I have the logic down, I thought it would be easy, but I haven’t been able to figure it out. There are some custom script examples, but without knowing what each line of code does in those examples, I can’t customize the custom scripts to my needs.

Are problems like these best solved by a custom script, or is it a use case to edit core files?
The custom script should be on which DocType? “Sales Order”, because the buttons are on that, or “Sales Invoice”, because that is what has to be loaded?


As you were able to do it in the sales_order.js so the custom script need to be done on that document (Sales Order). And how to do custom script, this is possible by writing custom script in the awesome bar or from Setup → Customize → Custom Script.

If you do not need to use custom script, then there is another long way that you can find it in this link:



Thank you for the reply. Yes I know I need to write a custom script, I just don’t know how. I have seen the custom script examples in the ERPNext tutorial, but I haven’t been able to use them for my objective. I need an example which is near to what I am trying to do. I want to do this with custom script only.
In short, when it goes to the sales invoice page, it should loop through the items in the Items table and look for any item which has the “to be drop shipped” checked. That should trigger the message.
Within the Sales invoice DocType there is a table names “items” and links to a DocType named “Sales Invoice Item”, so while trying to write the custom script , should I write:

frappe.ui.form.on('Sales Invoice', 'onload', function(frm) {
    $.each(frm.doc.sales_invoice_item, function() {
            msgprint('Check items for Drop shipping');

This ^ doesn’t work.

Yup learning is very often iterative slogging, overcoming gotchas and a confidence thing, where an indirect rather than a direct approach leads to the answer.

For clear good examples find some learning source for example JavaScript Tutorial

This helps if you work alone :slight_smile: Rubber duck debugging - Wikipedia

I will surely go through this tutorial. And I think the solution to my problem is simple, but I can’t figure it out.

Yes often just reading them is enough to get some Ah-ha clue trick or key to what you are missing - it’s usually on the end of your nose :slight_smile:

Google has useful guides too Chrome DevTools - Chrome Developers

Haven’t been able to crack this yet. Would like to do the course first but I am under a time constraint.
Is there a custom script repository, other than these ones:-