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.

Parsing a record's field values in mail script (display field values in notification)

Thomas_J_C
Mega Expert

I'm currently creating a mail script to query a Task's related records and display those related record's fields in a determined format. 

Querying the records I need is no problem, however, how would I go about getting each related record object and parsing the fields to string values to display in a mail script?

I've used the JSON.parse() method before in record producer's however that was for a variable and not a record object.

I'll provide a screenshot for reference. 

find_real_file.png

1 ACCEPTED SOLUTION

Hi Thomas,

so you can print them in email using

template.print(gr.source_ip);

what issue you are facing?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Thomas,

are you saying that you want to print the field label and field value in the email body like

Incident                    INC0001

Assignment Group     Service Desk

Do you want to print for all fields or for few?

sample script below:

var siarraTSK = current.sys_id;

var gr = new GlideRecord('tableName'); // use your table name here
gr.addQuery('siarra_task', siarraTSK);
gr.query();
if(gr.next()){
var recFields = gr.getFields();
for (i=0;i<recFields.size();i++)
{
var glideElement = recFields.get(i);
template.print('Field is ' + glideElement.getName() + ' Value is: ' + glideElement);
}
}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

My goal is to print all 6 specified field string values on each related record. The fields I would like print on each related record are:

user                 

source_ip

destination_ip

ports

service

protocol

direction

^

all of the above fields are string fields except for direction which is choice.

Hi Thomas,

so you can print them in email using

template.print(gr.source_ip);

what issue you are facing?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I had overthought the process, just the gr.fieldname worked.

 

Thank you!