Answered by:
Recipients.setAsync method (JavaScript API for Office) giving the error

Question
-
Hi,
I am getting below error -
"Uncaught Sys.ArgumentException: Sys.ArgumentException: Value does not fall within the expected range.
Parameter name: recipients"Below is code snippet:-
addressToAdd = {
displayName: Office.context.mailbox.userProfile.displayName,
emailAddress: Office.context.mailbox.userProfile.emailAddress
};Office.cast.item.toItemCompose(Office.context.mailbox.item).requiredAttendees.setAsync(addressToAdd, function (result) {
if (result.error) {
app.showNotification(result.error);
} else {
app.showNotification("Recipients overwritten");
}
});Immediate help is highly appreciated.
Thank you.
Tuesday, December 1, 2015 9:26 AM
Answers
-
Hi Sandip,
The parameter for the Recipients.setAsync should be an array. Please use [addressToAdd] instead of addressToAdd . Here is the correct format for your reference:
addressToAdd = { displayName: Office.context.mailbox.userProfile.displayName, emailAddress: Office.context.mailbox.userProfile.emailAddress }; Office.cast.item.toItemCompose(Office.context.mailbox.item).requiredAttendees.setAsync([addressToAdd], function (result) { if (result.error) { app.showNotification(result.error); } else { app.showNotification("Recipients overwritten"); } });
You can get more detail about this function from link below:
Recipients.setAsync method (JavaScript API for Office)
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Fei XueMicrosoft employee Friday, December 11, 2015 8:30 AM
- Marked as answer by Fei XueMicrosoft employee Monday, December 21, 2015 9:18 AM
Wednesday, December 2, 2015 2:25 AM -
Hi Sandip,
Sorry for the confusion.
The Recipients.setAsync is right method to book the room via Mail add-in. For this issue, please check the how you build for the addressToAdd variable.
In the original post, you were adding yourself to the recipients. If you want to book a room, we can get the room name and address via book it manually and then test it in the code.
Hope it is helpful.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Fei XueMicrosoft employee Friday, December 11, 2015 8:30 AM
- Marked as answer by Fei XueMicrosoft employee Monday, December 21, 2015 9:18 AM
- Unmarked as answer by Sandip Thombare Thursday, December 31, 2015 11:20 AM
- Marked as answer by Sandip Thombare Thursday, December 31, 2015 11:20 AM
Monday, December 7, 2015 7:00 AM
All replies
-
Hi Sandip,
The parameter for the Recipients.setAsync should be an array. Please use [addressToAdd] instead of addressToAdd . Here is the correct format for your reference:
addressToAdd = { displayName: Office.context.mailbox.userProfile.displayName, emailAddress: Office.context.mailbox.userProfile.emailAddress }; Office.cast.item.toItemCompose(Office.context.mailbox.item).requiredAttendees.setAsync([addressToAdd], function (result) { if (result.error) { app.showNotification(result.error); } else { app.showNotification("Recipients overwritten"); } });
You can get more detail about this function from link below:
Recipients.setAsync method (JavaScript API for Office)
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Fei XueMicrosoft employee Friday, December 11, 2015 8:30 AM
- Marked as answer by Fei XueMicrosoft employee Monday, December 21, 2015 9:18 AM
Wednesday, December 2, 2015 2:25 AM -
Hi Fei,
I have tried the corrected source code still getting below error.
Actually, my scenario is - In my office add-in, On checkbox click I want to set room name in add location text box as well as Attendees list & when I uncheck the checkbox I want to remove that room name from add location text box as well as Attendees list. Below is screen shot for same. Please help me on this.
Regards,
Sandip
- Edited by Sandip Thombare Wednesday, December 2, 2015 11:06 AM
Wednesday, December 2, 2015 11:05 AM -
Hi Sandip,
Based on my understanding, the Recipients.setAsyncis used to set the recipient list for an appointment or message.
If you want to set the room for the appointment, we can using code below:
Office.cast.item.toAppointmentCompose(item).location.setAsync("Room1");
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Thursday, December 3, 2015 7:22 AM -
Hi,
When we use your code it will add "Room1" to "add a location" text box only. Ideally It should also add to receipient list. Otherwise it will always show as free room. It will never be booked. This is how the Out of Box "Add Room" working.
Thank you.
Regards,
Sandip
Friday, December 4, 2015 5:43 AM -
Hi Sandip,
Sorry for the confusion.
The Recipients.setAsync is right method to book the room via Mail add-in. For this issue, please check the how you build for the addressToAdd variable.
In the original post, you were adding yourself to the recipients. If you want to book a room, we can get the room name and address via book it manually and then test it in the code.
Hope it is helpful.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Fei XueMicrosoft employee Friday, December 11, 2015 8:30 AM
- Marked as answer by Fei XueMicrosoft employee Monday, December 21, 2015 9:18 AM
- Unmarked as answer by Sandip Thombare Thursday, December 31, 2015 11:20 AM
- Marked as answer by Sandip Thombare Thursday, December 31, 2015 11:20 AM
Monday, December 7, 2015 7:00 AM -
Hi,
The Recipients.setAsync is right method to add the room to attendees list via Mail add-in. That's correct.
But, I want to clear the attendees list via Mail add-in. Please let me know if you find any solution.
Thank you.
Regards,
Sandip
Thursday, December 31, 2015 11:17 AM -
Hi Sandip,
Sorry for the later responding.
The Recipients.setAsync(recipients, optionsopt, callback) can used to overwrite the current recipient list. So we can use the code below to remove the all recipients:
Office.cast.item.toMessageCompose(item).to.setAsync([], function (result) { console.log(result.status); });
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Thursday, January 7, 2016 9:24 AM -
Hi Fei,
I have tried your code to set optionalAttedees as well as requiredAttendees i.e. overwrite the current recipient list. I havn't find anything for "to" i.e.
Office.cast.item.toMessageCompose(item).to.setAsync([], function (result) {})
When tried for optionalAttedees & requiredAttendees unfortunately, I am getting below error.
Thank you again for your response.
Regards,
Sandip
- Edited by Sandip Thombare Thursday, January 7, 2016 12:47 PM
Thursday, January 7, 2016 12:17 PM -
Hi Sandip, Did you ever get this to work? I am having same problem. My Outlook compose addin calls requiredAttendees.setAsync() with code that comes straight from MSDN example and I get "InternalFormatError" returned. Like you, I am also and looking for an API call that works like the out of the box "Add Room". That is, I was the room added to Location field and recipient list.
Thanks, Wendy
Thursday, March 31, 2016 6:49 PM