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

Ankur Bawiskar
Tera Patron
Tera Patron

@SM123 

share the logs to see if CC is present and also if query is giving the correct user

if (senderEmail == 'test@gmail.com' ) {
	gs.info('CC email' + email.cc);
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 
       gs.info('user found');
        current.caller_id = ccUserGR.sys_id;
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@SM123 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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