The CreatorCon Call for Content is officially open! Get started here.

How to reference catalog item variables in mail script?

Rich7
Tera Expert

I am fairly new to ServiceNow development and scripting.  I want to know how to reference variables from a User Approval step in a workflow.  The workflow is triggered by a Training Request that is picked from the Service Catalog.   

The goal is to present an email notification to the approver with all the variables the requestor filled out.  I want to use the runMailScript function in a Notification Email Script to do this but using current.variable.<variable_name> returns "undefined".  

I also want to know how to grab sys_id from the sc_req_item that was generated to be able to query its field values.

Any help is greatly appreciated.

Thanks,

Ritchie

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Ritchie,

 

Not sure if you got a chance to go through below links.

Variables in notifications

Variables in Task notifications

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

View solution in original post

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi Ritchie,

 

Not sure if you got a chance to go through below links.

Variables in notifications

Variables in Task notifications

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

The reason "current.variable.<variable_name>" isn't working for you is because the "current" record for approval notifications is the approval record itself which has no variables.  The linked training request is the record with the variables.

 

I would suggest looking at the out of the box "request.itil.approve.role" email template as an example.  When a catalog request requires approval, an email goes out summarizing all the requested items and includes the variables as well.  The message in that template has a script that captures the variables.  You will see it "dot-walks" to the sysapproval reference field which is a link to the request, and in your case should be the training request (assuming it extends the task table).

 

Thanks, looking at that template really helped.  Do you know what other methods can be used besides getLabel() and getDisplayValue().  I am trying to make the email dynamic which is why I created a mail script in the first place.