- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 01:41 PM
I have a workflow with a Notification Activity. I want it to send the email to the user who created the record that started the workflow. The table, u_infosec_risk_review has a column titled usubmitter. usubmitter has a default that populates the column with the sysid of the user who created the record.
I've searched for code to get the value in the Advanced Script and haven't found anything that's worked for me. I have tested it by hard-coding the sysid in the Advanced Script and it worked fine, so my issue is getting the actual value and not the assignment to the To: field.
Here's what I currently have:
// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
var gr= new GlideRecord('u_infosec_risk_review');
answer=gr.getValue('usubmitter');
Can anyone point me in the right direction on this?
Thanks,
Mike
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2019 08:33 AM
No problem. What you could do is:
1. replace the "Notification" activity with a new "Create Event" activity
You can create a new Event name by clicking on the magnifying glass to the right of the field, click on the "New" button and then fill out the form. I highly suggest using a "u." prefix to avoid any issues with SN creating the same one in the future.
Use the following code in the "Parameter 1" field so we can include the recipient in the event:
(function() {
// return the value to use for Parameter 1
return current.getValue("usubmitter");
}());
For now you can just disconnect the "Notification" activity so you don't lose anything:
2. create a new Notification record. On the "When to send" tab, set the "Send when" dropdown to "Event is fired" and then select the new Event name you just created
On the "Who will receive" tab, select the "Event parm 1 contains recipient" check box:
You may have to click on the "Advanced view" Related Link in order to see it:
OR, using the "Users/Group in fields" field, you could select the appropriate field that contains the recipient, in your case the "usubmitter" field. A no-code alternative where you would not need any code in the "Create Event" activity.
Now you have a Notification that can be easily maintained and any running workflows would get the updated one right away.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 01:46 PM
Try this out:
answer = (function(){
return current.getValue("usubmitter");
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 01:49 PM
That being said, I do not like adding notification activities in workflows because it is a pain to modify the notification afterwards - why edit a workflow when all you need is a tweak to the notification? And any running workflows would not get the updated notification.
I always raise an event instead and have the notification respond to that event.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 02:29 PM
Thanks, Jim.
That sounds like a great idea, but I'm unfamiliar with events. Still learning...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2019 08:33 AM
No problem. What you could do is:
1. replace the "Notification" activity with a new "Create Event" activity
You can create a new Event name by clicking on the magnifying glass to the right of the field, click on the "New" button and then fill out the form. I highly suggest using a "u." prefix to avoid any issues with SN creating the same one in the future.
Use the following code in the "Parameter 1" field so we can include the recipient in the event:
(function() {
// return the value to use for Parameter 1
return current.getValue("usubmitter");
}());
For now you can just disconnect the "Notification" activity so you don't lose anything:
2. create a new Notification record. On the "When to send" tab, set the "Send when" dropdown to "Event is fired" and then select the new Event name you just created
On the "Who will receive" tab, select the "Event parm 1 contains recipient" check box:
You may have to click on the "Advanced view" Related Link in order to see it:
OR, using the "Users/Group in fields" field, you could select the appropriate field that contains the recipient, in your case the "usubmitter" field. A no-code alternative where you would not need any code in the "Create Event" activity.
Now you have a Notification that can be easily maintained and any running workflows would get the updated one right away.