Getting Values of Fields to Text Editor Field when saving

@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 what fields ?

@bahaou

@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

@bahaou

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):wink:

 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","");}
}
}) ;

@misltechnical it should replace only the employee_name

@bahaou Yh. But it is still not replacing employee_name at least.

@misltechnical replace it with :
terms = terms.replace(“{{employee_name}}”,frm.doc.employee);

Wow Nice. It is working fine and as expected :heart_eyes::heart_eyes: 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 .

1 Like

@bahaou Thanks again :heart_eyes::heart_eyes:

1 Like

@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

frappe.utils.fmt_money(doc.money,currency="$")

@bahaou Where do I put this in that script?

@misltechnical just change the value with that . what have you written for the currency value ?


@bahaou Please check this

@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 ?