ATF || How to simulate sending an email to check Inbound email action

FrancoA
Tera Contributor

I´am trying to check if an inbound email triggers the creation of a record(Incident), i could not use the Generate Inbound Email action, because in my PDI does not work. 

I am using a server side script that creates the record.

(function(outputs, steps, stepResult, assertEqual) {


    var email = new GlideRecord('sys_email');
    email.initialize();
    email.type = 'received';
    email.subject = '1111';
    email.body_text = 'Test ATF inbound action - creating incident';
    email.from = 'atf-test@example.com';
    email.recipients = 'dev210439@service-now.com';
    email.mailbox = 'inbox';
    email.state = 'ready';
    var emailId = email.insert();

    if (!emailId) {
        stepResult.setFailed('No se pudo crear el sys_email');
        return;
    }


    var emailGr = new GlideRecord('sys_email');
    if (!emailGr.get(emailId)) {
        stepResult.setFailed('No se pudo recuperar el sys_email');
        return;
    }


    gs.eventQueue('email.read', emailGr, emailId, null);

 
    gs.sleep(10000);

   
    emailGr.get(emailId);
    gs.info('[ATF Test] Email state después de procesar: ' + emailGr.state);
    gs.info('[ATF Test] Email target_table: ' + emailGr.target_table);
    gs.info('[ATF Test] Email instance: ' + emailGr.instance);

    stepResult.setSuccess();

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

 But, it´s not working, when i check if the incident was created it fails. When i go to the created email, and reprocess, it works and creates the Incident.

 

Pls help!!

0 REPLIES 0