Send approval email to user stored in variable on catalog / request item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 03:49 PM
I am currently testing a file share request system for our service catalog. As part of this, the user will select the file share that they require access to from a drop down list. All of the file shares are stored in a module in the CMDB and have approvers listed for each file share.
Once you select the share from the drop down list, a catalog client script does a lookup and populates a field called 'Approver' with the users name. (this is a reference field which looks up the value from the sys_user table)
What I need to do is automate an email directly from the workflow on the service catalog which will email the approver to seek approval for access to the file share.
Has anybody done anything similar lately and if so, how can you do this. If possible, I would rather put the value into the "To" field on the email rather than the cc or bcc field.
I have had a look on here but have not been able to do this. Anybody got any ideas if this is possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 10:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 10:49 AM
Looks like you may want to use a run script activity instead of create event. Take a look at this:
Re: Pass a variable value into 'Parameter 1' in a Create Event workflow activity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 11:42 AM
Hi Brad,
You sir are a legend. That is working perfectly for me so far in my test workflow. Will look to build this into my overall workflow but should transfer across with no issues.
For any other noobies out there who may be looking at this thread in the future, here is how it is now set up and working.
Catalog Item:
Variable called test_user_name
This is a reference off the sys_user table
============================================================================================
System Policy > Events > Registry
Create registry entry with details as below:
============================================================================================
Workflow
Add a "Run Script" Activity which calls your event.
Code from the Run Script activity is as below:
var eventParm1 = current.variables.test_user_name.email; // This dot walks to the users email address from the sys_user table
gs.eventQueue("TestFileShareEventRegistry", current, eventParm1); // This line calls the event created above which will eventually be referenced in our notification.
============================================================================================
Email Notification
Table: Requested Item (NOTE: You may need to change this depending on what table you are working on)
Send When: Event is fired
Event Name: TestFileShareEventRegistry
Tick the "Event parm 1 contains recipient" option. This has been passed through in our "Run Script" activity in the workflow.
Message HTML: Create your email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 07:57 AM
Hi James
In your approver field you have username. You have to write script to get email of that approver and then push to the answer
Hope this helps
Thanks !
example below
===========
answer = [];
var gr=new GlideRecord('sys_user');
gr.addQuery('active', true);
gr.addQuery('name', current.variables.uservariable);
gr.query();
if(gr.next()){
answer.push(gr.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 09:46 AM
Ok, so I am a code newbie so please bear with me. From what I understand of the code above, it is looking to the sys_user table first.
It then looks for a match between the 'name' field (I assume on the sys_user table) and my variable on the RITM.
Then, as you have it above, it returns the sys_id so I need to change this to return the email address instead?
I have tried the following but still didn't work:
answer = [];
var gr=new GlideRecord('sys_user');
gr.addQuery('active', true);
gr.addQuery('name', current.variables.approver);
gr.query();
if(gr.next()){
answer.push(gr.email);
}
Is this correct?
I am putting this in the "To (script)" section on my notification on my workflow: