Multiple value in cc giving error in response body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 05:14 AM
I have configured outbound email integration through outbound rest message. I am facing one issue here when I am passing 1 email id in cc it is working fine and receiving email but when I am giving two mail id in cc it is not working and giving below error.
At least one recipient is not valid., Recipient 'brijmohan.kushwaha@test.com,vipul.agnihotri@test.com' is not resolved. All recipients must be resolved before a message can be submitted."}}
I am assuming there is issue with JSON structure in BR (sys_email table). How can I handle multiple id in cc. PFB code.
var body = current.body_text;
var subject = current.subject;
var restMessage = new sn_ws.RESTMessageV2('Email PoC', 'POST Email User');
// Set the request body
var requestBody = {
"message": {
"subject": current.getValue('subject'),
"body": {
"contentType": "html",
"content": current.getValue('body')
},
"toRecipients": [
{
"emailAddress": {
"address": current.getValue('direct')
}
}
],
"ccRecipients": [
{
"emailAddress": {
"address": current.getValue('copied')
}
}
]
},
"saveToSentItems": "true"
};
gs.info("test 3 "+requestBody +JSON.stringify(requestBody));
restMessage.setRequestBody(JSON.stringify(requestBody));
//restMessage.setRequestBody((requestBody));
// Send the REST message
gs.info("test 4 "+restMessage);
var response = restMessage.execute();
// Get the response details
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("test 1 "+responseBody);
gs.info("test 2 "+httpStatus);
We are getting below in response body.
Thanks & regards,
Brijmohan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 05:28 AM - edited ‎09-04-2023 05:28 AM
Hell @Brijmohan
Hope you are doing good!
I would like to understand how you are adding the CC email addressess in your rest message method. I mean how is the email triggered and using which method you are setting the email addresses.
Please revert back with the details so that we can more debug the same.
BR,
Kailash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 05:43 AM
Hi @Kailash Bhange, Thanks for your response. We have cc field on supplier form where we are storing all cc email id via inbound email integration. After that we have created notifications based on the condition. We have wrote one more before insert, update BR to setting the values in sys_email table for outgoing mail. PFB code.
var sp = new GlideRecord('sn_supplier_case');
sp.addQuery('sys_id', current.instance);
sp.query();
if (sp.next()) {
current.reply_to = sp.getValue('u_to');
current.user = sp.getValue('u_to');
current.copied = sp.getValue('u_cc');
current.direct = sp.getValue('u_from');
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 06:08 AM - edited ‎09-04-2023 06:09 AM
I think,
you should modify some script, maybe below example will help you.
consider I want to add user's email ids from xyz department. So i code it like below: -
var userMails = new GlideRecord("sys_user");
userMails .addQuery("department", 'XYZ');
userMails.query();
while(userMails.next()) {
email.addAddress("cc",userMails.getValue('email_address'),userMails.getValue('name'));
}
In your example I think, you have to push all CC email addressess to an array and for the length of array you will have to call this OOTB method from servicenow to set the CC email addressess.
Hope this helps.
If my answer resolves your issue, please mark my answer as ✅ Correct & Helpful based on the validations.
Thank You!
Regards,
Kailash
LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 06:57 AM
In cc, I am already getting all email id but issue is when I am executing the code is it considering only one value. Can you please help me how can i modified below code as your suggested approach.
var body = current.body_text;
var subject = current.subject;
var restMessage = new sn_ws.RESTMessageV2('Email PoC', 'POST Email User');
// Set the request body
var requestBody = {
"message": {
"subject": current.getValue('subject'),
"body": {
"contentType": "html",
"content": current.getValue('body')
},
"toRecipients": [
{
"emailAddress": {
"address": current.getValue('direct')
}
}
],
"ccRecipients": [
{
"emailAddress": {
"address": current.getValue('copied')
}
}
]
},
"saveToSentItems": "true"
};
gs.info("test 3 "+requestBody +JSON.stringify(requestBody));
restMessage.setRequestBody(JSON.stringify(requestBody));
//restMessage.setRequestBody((requestBody));
// Send the REST message
gs.info("test 4 "+restMessage);
var response = restMessage.execute();
// Get the response details
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("test 1 "+responseBody);
gs.info("test 2 "+httpStatus);