How to show pop up message to a specific user using js or python?
MCD-50
February 11, 2017, 3:08pm
2
var my_message = This is a warning message!
alert (my_message);
You can use frappe.msgprint
function too for the purpose.
2 Likes
i want to show pop message to a specific user only for an event.for example if i press save button in a doctype the pop up message should show only for the given user (message will be like user ‘user_name’ saved a ‘doctype_name’)
JS:
if(user=="user_login_id") {
frappe.msgprint("{0} save the doctype {1}", [user, doctype_name]);
}
Python:
if frappe.session.user == "user_login_id":
frappe.msgprint("{0} save the doctype {1}".format(frappe.session.user, doctype_name))
3 Likes
it is working only if specified user save a doctype.
i need like this.
there are two users in erpnext
1.user a
2.user b
both user a and b are logged in to erpnext.
if user a save a document type.pop up message should show for user b only.
Our client wanted an endpoint exposed.
We exposed it like this
For pop-up we’re using, frappe.publish_realtime()
i tried frappe.publish_realtime() but it is not working
for frappe.publish_realtime()
to work socketio must be running.
frappe.publish_realtime is working on production setup. It is not working on bench start
error in bench start
20:48:10 socketio.1 | listening on *: 9001
20:48:12 socketio.1 | { Error: connect ECONNREFUSED 0.0.0.0:8000
20:48:12 socketio.1 | at Object.exports._errnoException (util.js:1012:11)
20:48:12 socketio.1 | at exports._exceptionWithHostPort (util.js:1035:20)
20:48:12 socketio.1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
20:4…
opened 07:01AM - 11 Aug 16 UTC
closed 10:18AM - 11 Aug 16 UTC
Use case : To display a popup in ERPNext desk on REST API call.
https://github.… com/gaurav-naik/awfis_erpnext/blob/master/awfis_erpnext/awfis_erpnext/awf.py#L215
This is working successfully on a server running Frappe v7.0.16
![awf_popup_working](https://cloud.githubusercontent.com/assets/17795124/17580578/48aac0e2-5fbd-11e6-99bb-4407c3454550.png)
Feature stopped working after updating bench. Bench is currently on v7.0.19
Tried the following code as well. No exception raised, no popup either.
```
@frappe.whitelist(allow_guest=True)
def popuptest():
users = []
try:
for u in frappe.get_all("User", fields=['name'], filters={"role": "Sales User"}):
frappe.publish_realtime("msgprint", "Hello!", user=u.name)
users.append(u.name)
except Exception, e:
frappe.msgprint(e)
else:
frappe.msgprint("Published to: {u}".format(u=users))
```
how to run socketio in production mode
It automatically starts in production setup.
Check if it’s running
sudo supervisorctl status all
To setup socketio
bench setup socketio
https://frappe.github.io/frappe/user/en/bench/guides/setup-production.html
I am in production order
socket io working fine
frappe.publish_realtime() is not working.please check the attached picture
but pop up can not see for user hafeesk@gmail.com.i tried for all user but it is not working
try
frappe.publish_realtime(event='msgprint',message='hello',user='user@example.com')
Specify event
, message
and user
parameter, refer
os.remove(_file)
def is_file_old(file_path):
return ((time.time() - os.stat(file_path).st_mtime) > TASK_LOG_MAX_AGE)
def publish_progress(percent, title=None, doctype=None, docname=None):
publish_realtime('progress', {'percent': percent, 'title': title},
user=frappe.session.user, doctype=doctype, docname=docname)
def publish_realtime(event=None, message=None, room=None,
user=None, doctype=None, docname=None, task_id=None,
after_commit=False):
"""Publish real-time updates
:param event: Event name, like `task_progress` etc. that will be handled by the client (default is `task_progress` if within task or `global`)
: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
7 Likes