Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog Item Variables in Workflow Notification

nancyhz
Mega Contributor


I was asked to send a notification after task is closed in workflow.   The requirement is to use some Catalog Item form Variable values in email body. I don't how to get variable values in notification body.   Can I use :   ${workflow.variables.variableName} in email body?

 

Variable.png

12 REPLIES 12

marcguy
ServiceNow Employee
ServiceNow Employee

depending on what table your sending the notificaton from, the variable live on the sc_req_item table so if your sending from the sc_task (catalog task) table it would be current.request_item.variables.variablename



if it's from sc_req_item (the item itself) it would just be current.variables.variablename



here's a   pretty good examples of using them and actually printing the variable label etc.



Scripting for Email Notifications - ServiceNow Wiki


sam_hull
Kilo Expert

That is exactly what I use and it seems to work just fine for us: ${current.variables.nameOfVariable}


nancyhz
Mega Contributor

Thank you very much for your quick response.



One more question-   I want to send this notification to variable-project manager (referenced to user table)


in To (script) of Notification section (see my original post with screenshot), I wrote the following script:



// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.


answer =current.variable_pool.project_manager;



Is this right?





I'm not sure if your way will work or not because I've never tried it that way.   I was not able to get a variable reference into the TO: field unless I fed that variable into a field on the form first. Then you can just use that form field in the notifiction. But I have this mail script in the body of the email that added the person referenced in the variable (sys_user table) to the BCC field. I didn't do the CC field because our version of SN (Berlin) has a bug in it that doesn't allow the CC script:



<mail_script>


var supMail = current.variables.nameOfReferenceVariable.email;


var supName = current.variables.nameOfReferenceVariable.getDisplayValue();


email.addAddress("bcc", supMail, supName);


</mail_script>



This places that email in the BCC field. One caveat is that you still HAVE to have someone or a user field in the TO or it won't send. For us, that was fine, we wanted to also send the same notification to the opened_by. There is a tiny bit more on that here:



Scripting for Email Notifications - ServiceNow Wiki



Hope this helps a bit!