Using MediaWiki API for Showing content of Wikipedia page inside Dynamics 365 form
Views (809)
Hi,
Recently we had a requirement to show content of Wikipedia page and display it inside CRM in one of the entities form.
For this purpose, we can make use of “MediaWiki web service API.”
https://www.mediawiki.org/wiki/API:Main_page
To create the query, we can use the below tool
https://en.wikipedia.org/wiki/Special%3aApiSandbox
The html source code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
function SetWikiContent() {
// get country name from crm form
if (Xrm.Page.getAttribute("new_name") != null) {
var title = Xrm.Page.getAttribute("new_name").getValue();
// set the url
var url = "https://en.wikipedia.org/w/api.php?format=json&action=parse&page=" + title + "&prop=text§ion=0&callback=?";
$.getJSON(url, function (data) {
for (text in data.parse.text) {
var text = data.parse.text[text].split("
");
var pText = "";
for (p in text) {
//Remove html comment
text[p] = text[p].split("<!--");
if (text[p].length > 1) {
text[p][0] = text[p][0].split(/\r\n|\r|\n/);
text[p][0] = text[p][0][0];
text[p][0] += "
";
}
text[p] = text[p][0];
//Construct a string from paragraphs
if (text[p].indexOf("
") == text[p].length - 5) {
var htmlStrip = text[p].replace(/<(?:.|\n)*?>/gm, '') //Remove HTML
var splitNewline = htmlStrip.split(/\r\n|\r|\n/); //Split on newlines
for (newline in splitNewline) {
if (splitNewline[newline].substring(0, 11) != "Cite error:") {
pText += splitNewline[newline];
pText += "\n";
}
}
}
}
pText = pText.substring(0, pText.length - 2); //Remove extra newline
pText = pText.replace(/\[\d+\]/g, ""); //Remove reference tags (e.x. [1], [4], etc)
Xrm.Page.getAttribute('new_wikiinfo').setValue(pText);
}
});
}
}
</script>
</head>
<body onload="SetWikiContent();">
</body>
</html>


The helpful article
Hope it helps..
Filed under: CRM, CRM 2011, CRM 2013, CRM 2015, CRM 2016, CRM 2016 Update 1, Dynamics 365, Microsoft Dynamics 365, Microsoft Dynamics CRM Tagged: CRM 2011, CRM 2015, CRM 2016, CRM 2016 Update 1, CRM 4.0, Dynamics 365, Microsoft Dynamics CRM
This was originally posted here.

Like
Report
*This post is locked for comments