Hi Everyone,
I have a requirement to call CRM organisation service using javascript.
Actually, I have to create a HTML page and through it, I want to perform some action in CRM. That's why I want to call Organisation service using javascript.
Is it possible? If yes, can anyone suggest me a way.
Thank You
*This post is locked for comments
Hi Shalu,
For html/javascript use web api. On Sdk we have samples about this.
For Asp.net code you can do a reference to SDK libraries and call organization service. See sample code in C# on sdk.
Silvio.
Hi Shalu
Hope my Answer helps! I'd appreciate if you'd marking my Answering your question.
Thank You Swetha for your answer.
HI Shalu,
For calling CRM organization service your applicaation need to be authenticated which is not possible Using only javascript. You need to have Server side code. Either you use MVC application or normal web application
Hi Akhil,
I want to communicate with CRM through the html page using javascript and I need to host it somewhere.
Thanks
if you are not creating a web resource then are you developing any website and trying to connect to CRM from it?
Regards
AKHIL R
I was expecting this question.
I need to host it outside.
Hi Shalu,
If you are trying to access context information you can always add the below reference to your html web resource.
<script type="text/javascript" src="../ClientGlobalContext.js.aspx"></script>
Also if you want to make any changes to CRM entity records then always use Web Api. Please see the code below.
<script>
function Update(accountID){
var entity = {};
entity.accountcategorycode = 1;
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+accountID+")", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}
</script>
Import REST Builder Solution to your CRM organization and generate the above WEB API Request.
Regards
AKHIL R
Hi Shalu,
Can you details me more about the requirement ? Html page will be deployed with CRM as web resource or it will be hosted outside?
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6