web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Not able to connect to dynamic CRM on click of out look send button

(0) ShareShare
ReportReport
Posted on by 5

As the new meeting is created , all the meeting details like subject, organizer and start time of meeting all these details I want to store into the Dynamic CRM table on click of the outlook(app) send button.

I have followed this link and created one launcevent.js file and on onAppointmentSendHandler function write code for connecting to CRM and store the subject and organizer into tables, also used the Office.actions.associate but still when create new meeting on click of the send button I am getting your add-in is not available try after some time, also I have used the send mode property as 'Prompt User' I am also confused where I should use onAppointmentSendHandler or onItemSendHandler. any help on this will be really appreciated as I am struggling on this for a long time.

Here is my code for connecting to CRM in launchevent.js file

Office.onReady(function () {
// Set up onItemSend event handler
Office.context.mailbox.item.addHandlerAsync(
Office.EventType.ItemSend,
onItemSendHandler
);
});

function onItemSendHandler(eventArgs)
{
// Get the meeting subject and organizer
var subject = Office.context.mailbox.item.subject;
var organizer = Office.context.mailbox.item.organizer.displayName;

// Get the access token
getAccessToken(function (accessToken) {
// Create the CRM record
createCrmRecord(subject, organizer, accessToken);
});
}

function getAccessToken(callback) {
// Configure MSAL.js
const msalConfig = {
auth: {
clientId: 'clientid',
authority: 'login.microsoftonline.com/tennatId',
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: true
}
};
const msalInstance = new msal.PublicClientApplication(msalConfig);

// Get the access token
msalInstance.acquireTokenSilent({
scopes: ['crmurl.default']
}).then(function (authResult) {
const accessToken = authResult.accessToken;
callback(accessToken);
}).catch(function (error) {
console.error(error);
});
}

function createCrmRecord(subject, organizer, accessToken) {
// TODO: Implement your code to create the CRM record using the Web API.
// For example:

var endpointUrl = "crmurl/entityname";
var payload = {
"callsubject": subject,
"name": organizer
};
var xhr = new XMLHttpRequest();
xhr.open("POST", endpointUrl);
xhr.setRequestHeader("Authorization", "Bearer " + accessToken);
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.setRequestHeader("OData - MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.setRequestHeader("Prefer", "return=representation");

xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 204) {
console.log("Record created successfully.");
} else {
console.log("Error creating record: " + xhr.statusText);
}
}
};
xhr.send(JSON.stringify(payload));
}

if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
Office.actions.associate("onAppointmentSendHandler", onItemSendHandler);
}

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans