ERPNext Conference 2019* ERPNext.com Blog

Specific user to custom naming_series of an issue


#1

Hi all, i have try to limit a specific user to custom naming_series of an issue.
i have created 3 type of issue NCR-## NCF-## NCS-##
i have 3 Branch I need Link each branch to its own series automatically without the selection of the employee


#2

You can set the naming series automaticly with an custom script


#3

can you seed to me custom script


#4

therefore i need more information:
on wich conditions should the script take wich naming series?
how is the fieldname of the naming series called?


#5

fieldname is branch
like if branch == (almaza) aming_series == (Al-maza-)


#6

Try something like this:

frappe.ui.form.on('Issue', {
	before_save(frm) {
		if (frm.doc.branch == 'almaza') {
			cur_frm.set_value('naming_series', 'Al-maza-');
		}
	}
})

#7

not working
image
image

frappe.ui.form.on(‘Issue’, {
before_save(frm) {
if (frm.doc.branch == ‘Elkawsar’) {
cur_frm.set_value(‘naming_series’, ‘SI-ELkawsar-’);
}
}
})

Frappe Framework

Open Source Applications for the Web

Website: https://frappe.io

Source: https://github.com/frappe
Installed Apps

ERPNext: v12.1.5 (version-12)

Frappe Framework: v12.0.15 (version-12)

© Frappe Technologies Pvt. Ltd and contributors


#8

I think now I understand it!
you do not use the doctype “Issue” and a field of issue is “branch”, rather your doctype is called “Branch”!

So, let’s put the script you want into words;
When a new record (of doctype “Branch”) is created, the script should set the naming_series automatically. If the field “XXX” is the value “YYY”, the naming_series should be “ZZZ”.

Ist that correct? If yes, could you please define for me “XXX”, “YYY” and “ZZZ”?


#9

yes
If Branch== (Elkawsar) , Naming Series == (SI-ELkawsar-)
If Branch== (NOR) , Naming Series == (SI-NOR-)
If Branch== (Star) , Naming Series == (SI-Star-)
If Branch== (ASFour) , Naming Series == (SI-ASFour-)


#10

So you have in the doctype “Branch” also a field called “branch”??


#11

yes link field


#12

ok, and in the doctype"branch" you have also a field called “naming_series”, based on this the record will be named, correct?


#13

correct


#14

Well, then this should work:

frappe.ui.form.on('Branch', {
	before_save(frm) {
		if (frm.doc.branch == 'Elkawsar') {
			cur_frm.set_value('naming_series', 'SI-ELkawsar-');
		} else if (frm.doc.branch == 'NOR') {
			cur_frm.set_value('naming_series', 'SI-NOR-');
		} else if (frm.doc.branch == 'Star') {
			cur_frm.set_value('naming_series', 'SI-Star-');
		} else if (frm.doc.branch == 'ASFour') {
			cur_frm.set_value('naming_series', 'SI-ASFour-');
		}
	}
})

#15

thanks for help but still not working


#16

The code as itself is correct, so the problem have somewhere else.
What does youre webbrowser console logs say?


#17

the messaged is
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://raw.githubusercontent.com/frappe/emoji/master/emoji. (Reason: CORS request did not succeed)