How to populate sender's email address in a text field created on form, when email is sent

Damayanti Sarod
Tera Contributor

I have a requirement , wherein when a email sender sends a email to a specific email address,  his  email ID  should be populated on the field " Email ID of sender" which is created on case form.

1 REPLY 1

Yashsvi
Kilo Sage

Hi @Damayanti Sarod,

To achieve this requirement in ServiceNow, you can use an inbound email action to process the incoming email and populate the "Email ID of sender" field on the case form. Here are the steps to set this up:

  1. Create a Custom Field:

    • Ensure that you have a custom field on the case form named "Email ID of sender." This can be done by adding a new field to the sn_customerservice_case table.
  2. Create an Inbound Email Action:

    • Navigate to System Policy > Email > Inbound Actions.
    • Click on New to create a new inbound email action.
  3. Configure the Inbound Email Action:

    • Name: Give your inbound email action a name, like "Set Email ID of sender on Case."
    • Target Table: Set this to sn_customerservice_case.
    • Type: Choose New or Reply depending on whether you want to create a new case or update an existing one.

Condition:

 

 

email.to.indexOf("specific_email@example.com") > -1

 

 

 

  • Set the Actions:

    • In the Actions section, choose Set field values.
    • Field: Select your custom field "Email ID of sender."
    • Value: Use the sender's email address, which can be accessed using email.origemail in the script.
  • Add Script:

 

 

// Create a new Case record if the email action is of type 'New'
if (event.type == 'new') {
  var caseRecord = new GlideRecord('sn_customerservice_case');
  caseRecord.initialize();
  caseRecord.u_email_id_of_sender = email.origemail;  // Custom field
  caseRecord.short_description = email.subject;
  caseRecord.description = email.body_text;
  caseRecord.insert();
}

// If the email action is of type 'Reply', update an existing Case record
if (event.type == 'reply') {
  var caseRecord = new GlideRecord('sn_customerservice_case');
  if (caseRecord.get('number', email.watermark)) {
    caseRecord.u_email_id_of_sender = email.origemail;  // Custom field
    caseRecord.update();
  }
}

 

 

Save the Inbound Email Action:

  • Click Submit to save your inbound email action.

Thank you, please make helpful if you accept the solution.