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 :
Microsoft Dynamics CRM (Archived)

I am trying to create a dynamic table using html in CRM , I have developed below code but when deployed in CRM I am getting "Uncaught ReferenceError: XrmServiceToolkit is not defined" for libraries referred in the script tag. Kindly help out.

(0) ShareShare
ReportReport
Posted on by

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Dynamic Table</title>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}

table {
border: 1px solid #ccc;
border-collapse: collapse;
}

table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}

table th, table td {
padding: 5px;
border-color: #ccc;
}
</style>
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.2.custom.js"></script>
<script src="jqgrid/js/grid.locale-en.js" type="text/javascript"></script>
<script src="jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="../WebResources/Jquery.min.js" type="text/javascript"></script>
<script src="../WebResources/bootstrap.min.js" type="text/javascript"></script>
<script src="../WebResources/grid.locale_en.js" type="text/javascript"></script>
<script src="../WebResources/jquery.jqgrid.min.js" type="text/javascript"></script>
<script src="../WebResources/scripts/XrmServiceToolkit" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
debugger;
//setTimeout(2000, function ViewTable());

function ViewTable(){
//var newTable,startTag,endTag;
alert('query executed successfully');
var accountidtosearch = window.parent.Xrm.Page.data.entity.getId();

//if(accountid != null){

var query = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='contact'>"+
" <attribute name='fullname' />"+
" <attribute name='telephone1' />"+
" <attribute name='contactid' />"+
" <order attribute='fullname' descending='false' />"+
" <link-entity name='account' from='accountid' to='parentcustomerid' link-type='inner' alias='ab'>"+
" <filter type='and'>"+
" <condition attribute='accountnumber' operator='eq' value= '"+ accountidtosearch +"'/>"+
" </filter>"+
" </link-entity>"+
" </entity>"+
"</fetch>;"

//var encodedFetchXML = encodeURIComponent(query);
//Creating a new table


//executing above query

var contactsLog = new Array();
contactsLog.push(["Fullname", "telephone1", "contactid"]);
var contactRecords = XrmServiceToolkit.Soap.Fetch(query);

//Build an array containing Customer records.


if (contactRecords.length > 0)
{
alert('query executed successfully');

for (var contact = 0 ; contact < contactRecords.length; contact++)
{

contactsLog.push([
contactRecords[contact].attributes.new_name? contactRecords[contact].attributes.new_name.value : "",
contactRecords[contact].attributes.new_dates ? contactRecords[contact].attributes.new_dates.value : "",
contactRecords[contact].attributes.new_loopstring ? contactRecords[contact].attributes.new_loopstring.value : "",
]);



}

//Create a HTML Table element.
var table = document.createElement("TABLE");
table.border = "1";
//Get the count of columns.
var columnCount = contactsLog[0].length;
//Add the header row.
var row = table.insertRow(-1);
for (var i = 0; i < columnCount; i++) {
var headerCell = document.createElement("TH");
headerCell.innerHTML = contactsLog[0][i];
row.appendChild(headerCell);
}

//Add the data rows.

for (var i = 1; i < contactsLog.length; i++) {
row = table.insertRow(-1);
for (var j = 0; j < columnCount; j++) {
var cell = row.insertCell(-1);
cell.innerHTML = contactsLog[i][j];
}
}
var dvTable = document.getElementById("dvTable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
alert('updating table');


}
//}


//function getchildrecords()


}


</script>

</head>

<body onload="ViewTable()" style="overflow-wrap: break-word;">
<div id="dvTable">

</div>

</body>
</html>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The error simply means it cannot find the XrmServiceToolkit javascript web resource. This could be -

    1. You have not added this as a web resource in your CRM. Or

    2. You have added it but in a different lcoation and not "../WebResources/scripts/XrmServiceToolkit".

    You need to find this JS Web resource and ensure that it is getting referenced correctly from your html web resources. Read more about link the web resource here: docs.microsoft.com/.../webpage-html-web-resources

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    How you are showing the HTML page , is it inside the form or as a  popup window?

    If you are showing this inside form then check your URL you provided in the reference is not correct .  Lets take an example I have created one webresource like below -

    4621.toolkit.png

    Note:   I have hided the publishername from the name and the URL just before XrmServiceToolkit in above screenshot . 

    Now from HTML webresource you can get the reference using below line considering you are directly created the file under webresource.

     <script src="publishername_XrmServiceToolkit" type="text/javascript"></script>

    So you can create your own webresorce copy paste the same XrmServiceToolkit js  and take the reference in your HTML if you are not getting the reference.

    Hope this helps.

  • Suggested answer
    Prudvihub Profile Picture
    65 on at

    Take a look into below post i think its useful 

    prudvihub.blogspot.com/.../dynamically-create-html-table-in.html

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans