Java Script Code in MyApp

Hi everyone,
I am creating my own app and want to write some script code which is working from “Custom Script” but when i am creating .JS file and write same code it’s not working…Why…? Is there any check box same at is for “DOCTYPE”
Or changed something in Script,

Where are you adding your JS file?

In my Doctype folder…Where is all Doctype related file…!
Like i am creating Doctype is “My Invoice” SO under doctype folder “My Invoice” folder will create and all the related files is also generate automatically (PY,JSON)
Example as follows:

frappe-bench/apps/myApp/myApp/myModule/doctype/My Invoice/my_invoice.JS

@DNGupta

So when you open My Invoice form, your scripts aren’t working. Am I right? If yes, there could be something wrong with your js code. Check the browser’s console for errors.

Also try changing the extension to small-case .js

-Anand.

No no that i have created with small-latter. Here just for clear visual i had written with Capital latter…!
And yes It’s not working. I checked the browser’s console, there was no error. Some script code as follows which i am using (successfully from Custom Script but not woth JS file)

cur_frm.add_fetch(“link”,“source”,“target”)
frappe.ui.form.on(“My Invoice”,“rate”,function(frm)
{
frm.set_value(“cost”,frm.doc.rate * frm.doc.area);
});


Go to my settings in the menu bar and click on reload.

Yes that is for clear the cashe…I had done many time… but still it’s not working

@DNGupta have you set developer_mode = 1?

Do you have error in your console?

Usually the .js file just works, check if the file name is same as the .py file

Ooo Hi @rmehta … really thanks for reply @rmehta… I was decided to post again after some time because right now i am developing my application in V4 because of that script was not working in V5…! So first I’ll make app in v4 after I’ll install in V5…!
and Yes i have set that "developer_mode=1 and the file name is also same.
I am also getting confuse why only following codes are not working in V5

cur_frm.add_fetch(“link”,“source”,“target”)

frappe.ui.form.on(“Doctype”,“fieldName”,function(frm)
{
frm.set_value(“field1”,frm.doc.field2 * frm.doc.field3);
});


But working fine in V4

  • And i want to know if I’ll develop my application in V4 and will install in V5 it will work properly or not …?
    and please give the solution about this script also…Thanks in Advance

Works out of the box for most users, could be an issue with your setup. Without seeing a trace, its hard to tell.

Ok thanks @rmehta I’ll check again after finish the application…!
And can you tell me the table script to access all the child (Sales Taxes and Charges) table propriety or field
i am using following script which i found in one of forum post but it’s not working

cur.frm.cscript.child_table_field_name=function(doc,cdt,cdn)
{
var d=locals[cdt][cdn]
var cost_value=d.rate * d.units;
d.cost=cost_value;
refresh_field(“child_table_name”);
}


Please start a new query on a new thread.