Is it possible create Territory when i create a Project by client script. I any one know the solution please give any hints or sample code…
To create a Territory record on creation of a project record in ERPNext, you can use a client script . You can create a new client script via “New Client Script” in the toolbar. Select the type of client script: Form/DocType , List/Report , or Page . Set the DocType to Project and Event to onload . Then, you can write the code to create a Territory record in the client script. Here is an example of the code to create a Territory record in a client script:
frappe.ui.form.on('Project', {
onload: function(frm) {
frappe.call({
method: "frappe.client.insert",
args: {
"doc": {
"doctype": "Territory",
"territory_name": "New Territory",
"parent_territory": "Global",
"owner": "Administrator"
}
},
callback: function(r) {
console.log(r.message);
}
});
}
});
This code creates a new Territory record with the name “New Territory”, parent territory “Global”, and owner “Administrator” when a new Project record is created. You can modify the code to create a Territory record with the desired values.
1 Like