I have a workflow that runs whenever a new item is created in a list, and I want the workflow to execute a piece of JavaScript code. So far I haven't found a way to call a function through a workflow, so I was wondering if anyone might have an idea on how to do so.

The reason I need this is that instead of sending users an e-mail when a new item is added, I want to send them a notification message that appears on the top right corner on any page in the intranet whenever a new item was added somewhere.

It would also be ideal if I were able to pass variables from the workflow to the javascript code, such as the list item id and the title (to show them in the notification).

So basically, I just want to know how to trigger JavaScript code through a workflow and how to pass parameters and variables to the script. I'm using Nintex workflows.

Any suggestions would be greatly appreciated.

closed as off-topic by Eric Alexander Sep 10 '14 at 22:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • you'd be better off forgetting the workflow and adding some global code (either linked from the master page or through a custom action) that polls the list in question, say every five seconds, displaying a notification whenever it finds a new item. You can also get the ID, Title, and any other attribute you like in this manner. – Derek Gusoff Feb 26 '14 at 14:24
  • Why was this marked off-topic? The question is asking how to fire JavaScript from a WorkFlow. That's as on-topic as asking how to do anything else from a WorkFlow. – Christine Nov 29 '16 at 19:37

This would require you to only send JavaScript to a specific user in a specific session. I guess some technology like webworkers or SignalR could accomplish this, but it will be no easy solution.

Basically every user session would have to be connected to some sort of hub (SignalR) and then you would have to trigger an event in that hub, from your workflow, that in turn would push out the message to the user.

And one other culprit: how will you handle the scenario that the user is not connected to the intranet / SignalR hub? That is another big question you need to solve.

  • Regarding the user, I have another solution for that. Basically user X needs to click on a custom button first (example: "subscribe") to be "subscribed" to list X on the page. Clicking the button will run a JavaScript function that stores the ID of user Y in list Z on SharePoint. Then, when a new item is added to list X, I want the workflow to get all users stored in list Z and send them a notification (through JavaScript). – Magali Feb 26 '14 at 13:31
  • You would still have major problems with sending targeted messages that way. Javascript in essence does not work that way, and hence you will need to use some advanced framework like C# WebWorkers and SignalR to do the push notification (think of it like a chat client where you post a message from your workflow that then needs to find the correct users and show them the message) – Robert Lindgren Feb 26 '14 at 13:36
  • I am open to C# as well, but then I need to wait another month until I am allowed to use C# on our environment. – Magali Feb 26 '14 at 13:38
  • I understand that :) I'm just trying to tell you that this will be no walk-in-the-park even if you are a quite skilled developer in both C#, JavaScript and SharePoint in all (like for example delegate controls or Custom actions to inject your javascript code) – Robert Lindgren Feb 26 '14 at 13:39
  • Perhaps I need to look for a way to skip the workflow part. I haven't yet found a way to run JavaScript code when a new item is added to a list (since I can't use event handlers either) but I might just need to do some more research on that. I'm only skilled in JavaScript, anything client-side. I'm going to learn C# starting tomorrow and hope to have enough knowledge by the end of March, since many of the things I need to program would work so much better in C#. – Magali Feb 26 '14 at 13:41

This is the way I would do it:

  1. Create a new field on the list, for example: Notification (boolean), yes/no
  2. Create a user control or web part that use some server side logic to read the username and the list item property.
  3. On the user control you can do some jquery in the document.ready(), do some CSOM Calls to know if the property is set to yes, if its set to yes, then use a jquery plugin to show the notification.

like this one: https://stackoverflow.com/questions/10168757/how-to-load-this-jquery-notification-bar-on-page-load-instead-of-clicking-the-bu

http://tympanus.net/Development/jbar/ (click demo top)

  1. Include the webpart or usercontrol in the master page.

Not the answer you're looking for? Browse other questions tagged or ask your own question.