Getting Values of Fields to Text Editor Field when saving

We decided to create HR Letters through ERPNext. As in Job Offer doctype, We have created doctypes for Increment Letter, Warning Letters, Confirmation Letters, etc. and defined fields for the variables data. And created templates for letters in Terms and Conditions section according to information on Terms and Conditions section.

On Job Offer Doctype, when selecting the letter template, all the variable fields are filling automatically from the entered values and letter is automatically generated. After all, we can edit the letter contents in that text editor field.

But for the doctypes that I created, those values not fetching. How to fetch field values to text editor as similar to Job Offer doctype?

@misltechnical that’s a custom script you need to create .
the scripts you may use are here

your event goes like this. when you change the name of the letter execute some code : get the letter from the database with its values , then insert the to the fields you want

1 Like

@bahaou Thanks for your suggestion. Can you please provide the script, because i’m new to erpnext scripts. Just used the customizations from Interface level.

@misltechnical are using the same doctype letter template ?

@bahaou No. Letter Templates are in ‘Terms and Conditions’ DocType.

@misltechnical I will provide you a code later , I m really busy at work .

1 Like

Thanks alot. It will be a great help because we are stuck in the middle of process due to this. :heart_eyes:

@misltechnical hello sir

Hello :innocent:

@misltechnical did you came out to a solution ?

@bahaou Not Yet :neutral_face:

@misltechnical ok give the exact scenario , and the name of doctypes (which ones you created).

I created a Doctype Named : Salary Increment Letter, In that doctype I have three fields named : employee_name, effective_date, basic_salary. I manually enter the values to those fields.
Then I have created a Link Field named “select_terms” to select the predefined letter template. When selecting the template, I need to load the letter to Text Editor field named “terms” with automatically filling the above field values.

Letter Formats are created in “Terms and Conditions” doctype.

Letter format example :

Date: {{ effective_date}}

From:
HR Manager,
TSH (Pvt) Ltd.

To:
{{ employee_name }},

Confirmation of Salary Increment

Dear {{employee_name}},

We are pleased to inform you that, the management has decided to bring your salary up to with effective date from {{effective_date}} considering your performance throughout the period from your confirmation.

Yours Faithfully,
HR Team

@misltechnical
create a custom script on the doctype Salary Increment Letter . enable it and try this code :

 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;
            frm.set_value("terms",terms);
            
        }
    }
});
	    
	    
	
	}
	else {frm.set_value("terms","");}
}
}) 

note that if you write the code inside the doctype folder in the js file , the execution will be a little bit faster . but this will works as well .

1 Like

@bahaou Thank You for your valuable time. But still its not working. What will be the issue. :thinking::neutral_face:

@misltechnical can you share some screenshots . I tested it the way you did it and it works for me

@bahaou Please check following screenshots.

@misltechnical okay , did it work ?

@bahaou No :cold_sweat: Its not working.

@misltechnical but in the screenshot , the terms editor has data in it .is it what are you trying to accomplish ?