Frappe.msgprint / frappe.throw problem

Hi All,

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

below is the screenshot of the code. Thanks :slight_smile:

@kenny, try with this -

frappe.throw((“Your Message.”))

1 Like

@priya_s

thanks for the help but it still didn’t show any error message when save the button.

This is the customize doctype. If you need any extra information. I can provide you. Thanks ya.

@kenny, Please check first your if chk-godplateslots : condition is true or not otherwise share your code.

1 Like

@priya_s frappe.throw((“Your Message.”))

if i remove that conditional, the frappe.throw didn’t work 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

Hi @kenny,

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").

Hope it helps.

1 Like

hi @littehera

thanks for the guide.:grin:

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.

below is the code modified after your suggestion.

@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.”))

1 Like

@kenny, @littlehera, @priya_s

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)

5 Likes

Sorry to trouble @priya_s, @littlehera, and @makarand_b

Thanks @makarand_b, i learn that frappe.msgprint(“Your Error Message”, raise_exception=True) can work as frappe.throw also.

@priya_s, i didn’t use frappe.throw is cause of it didn’t work as it didn’t have any response after i save the form.

I able to use frappe.throw by rebooting the server. Really sorry for any inconveniences caused.:joy:

Lol. It’s okay kenny. :smiley:

Thanks @makarand_b! Learned something new. :slight_smile: