Skip to main content

Notifications

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);
}

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans