I succeeded to play popup message to be an pop notification using hooks (using scheduler event), but the problem that this message is disappearing once the user is clicking on any place at the screen and that will let the message to disappear. I used:
frappe.publish_realtime(event=‘msgprint’, message=‘Popup Msg As Test’, user=frappe.session.user,doctype=‘Trip Order’)
I am sure there should be a way to display the message in dialogue box and stay on the screen until user close it or bless on any button related to this message.
The problem that all the dialogues that mentioned in this link: Dialogs Types are required to be written in .js and because I need to execute the script from hooks, so I need it to be written by python
The event here doesn’t correspond to the method you want to call from the server/client side, but rather the event that you’ll be passing from the server to the client.
As an example, see the event setup_task in the setup wizard used to execute .js code from .py:
The primary purpose of frappe.publish_realtime() is to call client-side scripts via the server side. So, I think even if you call your .py function via hooks, you can use this functionality to render any .js dialog you want. You can also pass all relevant parameters you may need from .py in the second argument of publish_realtime, like the data passed in the above example.
The main problem I am facing now that if I displayed a message using msgprint or using frappe.confirm or using show_alert, when the user click on any place at the screen, the message will disappear.
How can I disallow the message from being disappear and making the button selection to be obligatory to disappear? I need to confirm that the user read the message.
From the other side, I was trying to write a method in .js and calling it from .py using publish_realtime, and it worked but it was required that the document to be opened. So for example, if I need to display the alert using this method in javascript, I have to be at the document it self. I placed this method under onload and I placed it under setup and in all the cases, I have to be in the document it self.
As I am going to run this method using hooks and schedule, so how I can place this javascript method in a place that will be executed even I am at the desktop of the erpnext and not at the document it self?
It is working only if I am at Trip Order document.
But I need it to work even if I am at the desktop or any other module in the ERPNext.
I tried to place frappe.realtime.on("display_notification", function(data) under onload:function(frm) and the same thing, I have to be at the Trip Order document to get the message.
I need the display_notification to be executed from all modules or if I am at the desktop screen of the ERPNext and not to be a condition that the Trip Order document to be opened. How?
I need to use cur_frm.set_value("last_note_time", cur_time) from frappe.publish_realtime using eval_js as it is assumed to run it as javascript, I tried the below in python but it did not work:
Thank you @Mohammed_Redha.
My problem with frappe.session.user that is always return Administrator even the logged in user is other than Administrator. Why? What it should normally return?
Also, if I need to notify all the logged in users, what should I pass for user argument in publish_real?
@rahy No, you can read the documentation of that function :
"""Publish real-time updates
:param event: Event name, like `task_progress` etc.
:param message: JSON message object. For async must contain `task_id`
:param room: Room in which to publish update (default entire site)
:param user: Transmit to user
:param doctype: Transmit to doctype, docname
:param docname: Transmit to doctype, docname
:param after_commit: (default False) will emit after current transaction is committed
"""