I am having some problem when using the frappe.throw or validated = false command.
Am i forgot to import any library?
If i use frappe.msgprint without validated = false, it is working
if i use frappe.throw, it is not working
if i use frappe.msgprint and validated = false, it is not working also
If i use frappe.msgprint without validated = false, it is working
if i use frappe.throw, it is not working
if i use frappe.msgprint and validated = false, it is not working again
is it i import wrong library?
when the doctype been created, there only have these 3 lines.
from future import unicode_literals
import frappe
from frappe.model.document import Document
Youâve imported the correct library (import frappe). Try removing the underscore and inner parenthesis pair and just use frappe.msgprint("Block and Level already exist") or frappe.throw("Block and Level already exist").
i try frappe.msgprint(âBlock and Level already existâ). it is working but the record is been created.
I should use validated = false right?
after i add in the validated = false into the code, it canât be save.
Do i need to import another library for validated = false ?
frappe.throw(âBlock and Level already existâ) somehow didnât work.
@kenny, msgprint is used for only show pop-up message thats why record get created. So, you should use frappe.thow for throwing exception.
Here is sample code and it works for me -
if len((doc.ship_name).replace(â â,â')) < 3 :
frappe.throw((ââShip Nameâ must be at least three characters.â))
You can use the frappe.msgprint to raise the error as well, as the frappe.throw internally uses the frappe.msgprint.
To raise exception using frappe.msgprint pass the argument raise_exception in raise_exception you can pass the exception class like frappe.ValidationError or True.
So you can use the frappe.msgprint("Your Error Message", raise_exception=True)