How to write a abbreviation in a field Related with in another field Value in same doctype

I have faced some issues with Journal Entry Doctype. In the Journal Entry Doctype under the “Entry Type” label (field name: voucher_type) contain
image

16 options. so I need to create and store abbreviations of those entry types in another field and also need to change the Entry abbreviation by changing the Entry type.



I need the following answer after I changed the Entry Type in the Journal Entry doctype

newly created field (Entry Abbr) details

thanks
Dilum

Hi @Dilum_Chaminda,

That for, please apply the client script.

frappe.ui.form.on('Journal Entry', {
	refresh: function(frm) {
		frm.trigger('voucher_type');
	},
	voucher_type: function(frm) {
		if (frm.doc.voucher_type == "Journal Entry") {
		    frm.set_value('entry_abbr', "JE");
		} else if (frm.doc.voucher_type == "Inter Company Journal Entry") {
		    frm.set_value('entry_abbr', "IC");
		} else if (frm.doc.voucher_type == "Bank Entry") {
		    frm.set_value('entry_abbr', "BK");
		} else if (frm.doc.voucher_type == "Cash Entry") {
		    frm.set_value('entry_abbr', "CH");
		} else if (frm.doc.voucher_type == "Credit Card Entry") {
		    frm.set_value('entry_abbr', "CC");
		} else if (frm.doc.voucher_type == "Debit Note") {
		    frm.set_value('entry_abbr', "DN");
		} else if (frm.doc.voucher_type == "Credit Note") {
		    frm.set_value('entry_abbr', "CN");
		} else if (frm.doc.voucher_type == "Contra Entry") {
		    frm.set_value('entry_abbr', "CE");
		} else if (frm.doc.voucher_type == "Excise Entry") {
		    frm.set_value('entry_abbr', "EE");
		} else if (frm.doc.voucher_type == "Write Off Entry") {
		    frm.set_value('entry_abbr', "WO");
		} else if (frm.doc.voucher_type == "Opening Entry") {
		    frm.set_value('entry_abbr', "OE");
		} else if (frm.doc.voucher_type == "Depreciation Entry") {
		    frm.set_value('entry_abbr', "DP");
		} else if (frm.doc.voucher_type == "Exchange Rate Revaluation") {
		    frm.set_value('entry_abbr', "ER");
		} else if (frm.doc.voucher_type == "Exchange Gain Or Loss") {
		    frm.set_value('entry_abbr', "EG");
		} else if (frm.doc.voucher_type == "Deferred Revenue") {
		    frm.set_value('entry_abbr', "DR");
		} else if (frm.doc.voucher_type == "Deferred Expense") {
		    frm.set_value('entry_abbr', "DE");
		}
	}
});

Please check your field name and entry_abbr according.

Thank You!

1 Like

Hi @NCP
Thank you very much. It is working perfectly.
Thank You!

The above solution work perfectly for related to a single field.
If I select “Bank Entry” in the Entry type there are another two options (Receive and Pay) of Payment Type effect creating an Entry Abbreviation field. that means creating an Entry Abbreviation effect two fields “Entry type” and “Payment Type”.


how can we modify the above script for this situation?
thanks
Dilum

Hi @Dilum_Chaminda,

please apply it.

		else if (frm.doc.voucher_type == "Bank Entry") {
		    if (frm.doc.payment_type == "Receive") {
		        frm.set_value('entry_abbr', "BKR");
		    } else if (frm.doc.payment_type == "Pay") {
		        frm.set_value('entry_abbr', "BKP");
		    }
		}

And also add another event.

	payment_type: function(frm) {
		frm.trigger('voucher_type');
	},

Thank You!

1 Like

hi @NCP, The above solution is working perfectly.
thank you
Dilum