Send approval email to user stored in variable on catalog / request item

jfinn
Kilo Expert

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?

14 REPLIES 14

If I remove the ${.........} from the Parameter 1 field, I don't get the error message but I cannot see anything in the Event logs so it looks like my event is not being fired.



Am I missing a step here?



find_real_file.png


Brad Tilton
ServiceNow Employee
ServiceNow Employee

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


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



find_real_file.png




find_real_file.png




find_real_file.png




============================================================================================



System Policy   >   Events   >   Registry



Create registry entry with details as below:


find_real_file.png




============================================================================================



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.


find_real_file.png


find_real_file.png



============================================================================================



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


find_real_file.png





Tick the "Event parm 1 contains recipient" option.   This has been passed through in our "Run Script" activity in the workflow.


find_real_file.png



Message HTML:   Create your email notification


find_real_file.png


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);


      }


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:



To Script.JPG