Unable to insert doc from customscript

Hi guys,

I have read frappe cheatsheet and some of the code provided on github. Unfortunately still unable to insert doc after creating another. Main doc is SA Cargo, doc which should be inserted is SA Subcargo.

Here is the code:

frappe.ui.form.on(“SA Cargo”, “refresh”, function (frm) {
if(!frm.doc.__islocal)
{
doc = frappe.doc({
“doctype”: “SA Subcargo”,
“cargo_name”: “AAAA”,
“un_number”: “AABB”
})
doc.insert()
}
});

In addition I have removed mandatory fields but still I am getting:
“SAVING” and greyed out screen. My goal is to insert document automatically without user input.

Update:
Even if I go with the example:

frappe.ui.form.on(“SA Cargo”, “refresh”, function (frm) {
if(!frm.doc.__islocal)
{
todo = frappe.get_doc({“doctype”:“ToDo”, “description”: “test”})
todo.insert()

   }

});

I get exactly the same thing (greyed out screen and “Saving”). One thing to note is that the SA Cargo document is saved properly :slight_smile:

Thank you in advance.

Once again I have felt into misleading documentation trap - will fix it for new users. Please close this topic.

Note:
For above operation go for CRUD operations:
https://frappe.github.io/frappe/user/fr/guides/integration/rest_api.html

1 Like