@bahaou When selecting the Letter from “Select Terms and Condtions”, then the content is loading. At that moment, I need to get the details of above fields.
@misltechnical I thought you only wanted to put the terms in the text editor ? FROM WHERE you are gonna load the employee name ? please give some good explanations
I have employee name, date and basic salary in the same doc. First I type those values in it. Then I select the Letter format from “Select Terms and Condtions”. Then the letter should be there with above values in the letter.
@misltechnical ok ok I got you . does the code above load the terms first ? if yes , try to put this line before (frm.set_value(“terms”,terms)
terms.replace("{{employee_name}}",frm.doc.employee);
select the employee before selecting the term
try this and let me know
@bahaou Is this Correct? If it is correct, the values are not loading. The Terms are loading fine. But the values are not there.
frappe.ui.form.on('Salary Increment Letter', {
select_terms : function (frm) {
if (frm.doc.select_terms){
frappe.call({
method: "frappe.client.get",
args: {
doctype: "Terms and Conditions",
name: frm.doc.select_terms,
},
callback(r) {
if(r.message) {
var terms = r.message.terms;
terms.replace("{{employee_name}}",frm.doc.employee);
frm.set_value("terms",terms);
}
}
});
}
else {frm.set_value("terms","");}
}
}) ;
Wow Nice. It is working fine and as expected Thanks alot for your Time and Everything.
frappe.ui.form.on('Salary Increment Letter', {
select_terms : function (frm) {
if (frm.doc.select_terms){
frappe.call({
method: "frappe.client.get",
args: {
doctype: "Terms and Conditions",
name: frm.doc.select_terms,
},
callback(r) {
if(r.message) {
var terms = r.message.terms;
terms = terms.replace("{{employee_name}}",frm.doc.employee_name);
frm.set_value("terms",terms);
}
}
});
}
else {frm.set_value("terms","");}
}
}) ;
you need to change {{employee_name}} to be without spaces otherwise you need more code to figure it out . you also need other scripts on all the other fields to change the values when they do , like when you change the employee after selecting terms, name should change again . give it a try .
@bahaou One last thing, Do you know how to format a currency value. Because currency values are getting as plain numbers without formatting.
Ex : 2,300.00 is getting as 2300 to the letter.
@misltechnical whe you replaces the filed just change the value doc.money with frappe.utils.fmt_money(doc.money,currency=“$”)
@misltechnical that’s not gonna work sorry . you need to use another call function . may I ask you something ? are you trying to print that letter to be well formatted ?