Add Email CC in caller field in inbound action

SM123
Tera Expert

Hello All,

I need a quick help in my inbound action.

I have a scenario in which i have to add CC user to caller field when email is coming from certain user. Can anyone help me what is wrong in my code. Usually, it will be single person in CC, but i tried with array too still there is no luck

if (senderEmail == 'test@gmail.com' ) {
	
if (email.cc) {  // Ensure CC exists
    var ccUserEmail = email.cc.toString().trim(); // Convert to string and remove spaces
    var ccUserGR = new GlideRecord('sys_user');
    ccUserGR.addQuery('email', ccUserEmail);
    ccUserGR.query();

    if (ccUserGR.next()) {  // If user found, assign to Caller 
        current.caller_id = ccUserGR.sys_id;
      
    }
}
if (senderEmail == 'test@gmail.com' ) {
if (email.cc && email.cc.length > 0) {  
    var ccEmails = email.cc.toString().split(','); // Convert to list if needed
    var ccUserEmail = ccEmails[0].trim(); // Get first email from CC

    var ccUserGR = new GlideRecord('sys_user');
    ccUserGR.addQuery('email', ccUserEmail);
    ccUserGR.query();

    if (ccUserGR.next()) {  
        current.caller_id = ccUserGR.sys_id;
        
    }
}
}

  

1 ACCEPTED SOLUTION

Animesh Das2
Mega Sage

Hi @SM123 ,

 

It seems 'email.cc' is not a valid property, please try using 'email.copied' instead and see if that works.

'email.copied' contains a comma-separated list of email addresses in the Cc.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

View solution in original post

6 REPLIES 6

Animesh Das2
Mega Sage

Hi @SM123 ,

 

It seems 'email.cc' is not a valid property, please try using 'email.copied' instead and see if that works.

'email.copied' contains a comma-separated list of email addresses in the Cc.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

Hi @Animesh Das2 ,

I tried but still not working.

if (email.copied && email.copied.length > 0) {  
    var ccEmails = email.copied.toString().split(','); // Convert to list if needed
    var ccUserEmail = ccEmails[0].trim(); // Get first email from CC

    var ccUserGR = new GlideRecord('sys_user');
    ccUserGR.addQuery('email', ccUserEmail);
    ccUserGR.query();

    if (ccUserGR.next()) {  
        current.caller_id = ccUserGR.sys_id;
        
    }

@SM123 ,

 

Can you verify first if you are getting the value of email.copied at all, preferably for a single email address in CC? If yes then, if it is a new record to create then try with current.insert() at the end or if it is an update to the record then try with current.update() if that helps.

 

If you still face any issue, share the SS of the 'Inbound email action' along with 'When to run' field values for more understanding.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

 

 

Hi @SM123 
Try:

 var ccemail = email.copied; // Ensure 'copied' field is retrieved correctly
    if (ccemail) {  
        var ccEmails = ccemail.toString().split(','); // Convert to list
        if (ccEmails.length > 0) {
            var ccUserEmail = ccEmails[0].trim(); // Get first email and trim spaces
            var ccUserGR = new GlideRecord('sys_user');
            ccUserGR.addQuery('email', ccUserEmail);
            ccUserGR.query();

            if (ccUserGR.next()) {  
               var userid = ccUserGR.sys_id;
               current.caller = userid;
                }

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

Thank You!