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.

How to check Email record in ATF

Pravallika9
Tera Expert

Hi,

When a request is approved or rejected mail is sent to requested for.

ATF step, i have written a record query for sys_email table.

find_real_file.png

I am getting below error.

find_real_file.png

I am getting sys id of the ritm that is why it is failing may be.

How to get the exact record.

1 ACCEPTED SOLUTION

Hi,

the issue here is target field on sys_email is document_id so possibly it is not able to query

Use Run Server Side Script Step instead of Step 22 which is Record Query

(function(outputs, steps, stepResult, assertEqual) {
// add test script here

var STEP_10_SYS_ID= 'd9f8dd67db805410bea7550a48961930'; // step sys_id of Step 10

var val = steps(STEP_10_SYS_ID).first_record;

var emailRec = new GlideRecord('sys_email');
emailRec.addQuery('target_table', 'sc_req_item');
emailRec.addQuery('instance', val);
emailRec.query();
if(emailRec.next()){

outputs.table = 'sys_email';
outputs.record_id = emailRec.sys_id;

message = 'Found Email';
stepResult.setOutputMessage(message);

stepResult.setSuccess();
return true;
}
else{
message = 'Not Found Email';
stepResult.setOutputMessage(message);
stepResult.setFailed();
return false;
}

})(outputs, steps, stepResult, assertEqual);

Then For Step 23 do this select the output of the previous Run Server side script step

"Open the 'Email' form with id '{{Step 22: Record Query.Record id}}'

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Yes Ankur

Mail is generating manually.

Hi,

the issue here is target field on sys_email is document_id so possibly it is not able to query

Use Run Server Side Script Step instead of Step 22 which is Record Query

(function(outputs, steps, stepResult, assertEqual) {
// add test script here

var STEP_10_SYS_ID= 'd9f8dd67db805410bea7550a48961930'; // step sys_id of Step 10

var val = steps(STEP_10_SYS_ID).first_record;

var emailRec = new GlideRecord('sys_email');
emailRec.addQuery('target_table', 'sc_req_item');
emailRec.addQuery('instance', val);
emailRec.query();
if(emailRec.next()){

outputs.table = 'sys_email';
outputs.record_id = emailRec.sys_id;

message = 'Found Email';
stepResult.setOutputMessage(message);

stepResult.setSuccess();
return true;
}
else{
message = 'Not Found Email';
stepResult.setOutputMessage(message);
stepResult.setFailed();
return false;
}

})(outputs, steps, stepResult, assertEqual);

Then For Step 23 do this select the output of the previous Run Server side script step

"Open the 'Email' form with id '{{Step 22: Record Query.Record id}}'

Regards
Ankur

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

Thanks it worked

Glad to help.

Please mark appropriate response helpful as well.

Regards
Ankur

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