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)

Issue referencing JS files in html web resource page CRM 2013

(0) ShareShare
ReportReport
Posted on by

I have following web page html resource in CRM 2013 (see below), I created the JS Scripts as web resources with names also below and reference them in the page, however I can't seem to get XrmSvcToolKit.fetch working (see line in RED), I always get "fetch is not a property referenced", I have the same process only using full JS in another solution same server that throws an alert box and that works perfect. Same JS's.

Any help would be greatly appreciated.

G

=======================

<!DOCTYPE html >

<html lang="en-us">

<head>

<title>Query By ANI Page</title>

<script type="text/javascript" src="dev_jquery.js"></script>
<script type="text/javascript" src="dev_json2.js"></script>
<script type="text/javascript" src="dev_XrmSvcToolKit.js"></script>

<style type="text/css">
body {
font-family: Segoe UI, Tahoma, Arial;
background-color: #d6e8ff;
}

tbody {
background-color: white;
}

th {
background-color: black;
color: White;
}
</style>

<script type="text/javascript">
document.onreadystatechange = function() {
if (document.readyState == "complete") {
getDataParam();
}
}

function getDataParam() {
//Get the any query string parameters and load them into the vals array
var vals = new Array();

if (location.search != "") {
vals = location.search.substr(1).split("&");

for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}

//Look for the parameter named 'data'
var found = false;

for (var i in vals) {
if (vals[i][0].toLowerCase() == "data") {
parseDataValue(vals[i][1]);
found = true;
break;
}
}

if (!found) {
noParams();
}
} else {
noParams();
}
}

function queryByANI(datavalue) {

if (datavalue != "") {

alert(datavalue);


var accountFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='account'>" +
" <attribute name='name' />" +
" <attribute name='primarycontactid' />" +
" <attribute name='telephone1' />" +
" <attribute name='accountid' />" +
" <order attribute='name' descending='false' />" +
" <filter type='and'>" +
" <condition attribute='telephone1' operator='eq' value='" + datavalue + "' />" +
" </filter>" +
" </entity>" +
"</fetch>";

DOESN'T REFERENCE XRMSVCTOOLKIT

var retrievedate = XrmSvcToolkit.fetch({
fetchXml: accountFetchXML,
async: false,
successCallback: function(result) {
return result.entities[0].accountid;
},
errorCallback: function(error) {
throw error;
}
});
} else {
noParams();
}
}

function parseDataValue(datavalue) {
if (datavalue != "") {

var vals = new Array();
vals = decodeURIComponent(datavalue).split("&");

for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}

document.getElementById("ANI").value = vals[i][0];

} else {
noParams();
}
}

function openPage()
{
var ANIResult = queryByANI(document.getElementById("ANI").value);
location.href = "xxxxxxx_dev/main.aspx;pagetype=entityrecord&id=%7B"+ ANIResult +"%7D";
}

function noParams() {
var message = document.createElement("p");
setText(message, "No ANI was passed to this page");
document.body.appendChild(message);
}

//Added for cross browser support.
function setText(element, text) {
if (typeof element.innerText != "undefined") {
element.innerText = text;
} else {
element.textContent = text;
}
}
</script>

</head>

<body>
<p>Based on the ANI passed, you can jump to the Account using the link below:</p>
<table>
<thead>
<tr>
<th>ANI</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" id="ANI"></td>
<td><a href ="javascript:openPage()">Account Link</a></td>
</tr>
</tbody>
</table>
</body>

</html>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    This is likely because of the names of your webresources - if you have a forwardslash in the name, then you'll need to treat the folders in the same way you would if they were physical files.

    If you have

    dev_/html/Page.htm

    dev_/js/Script.js

    You would need to reference the script from the page.htm as :

    <script type="text/javascript" src="../js/script.js"></script>

    Notice how the src link is using a relative url so that caching is correctly used.

    See my post on this - develop1.net/.../CRM-Developer-e28098Must-Knowe28099-2-Web-Resource-Caching.aspx

    Hope this helps

  • Community Member Profile Picture
    on at

    Still have the issue (screenshot_1), in screenshot_2 you can see the reference to the JS scripts, matter of fact I'm using CDN for the Jquery and Json2, the third one is XrmSvcToolkit which doesn't have a CDN but I created it as a web resource locally. You can see it along the other web resources in screenshot_3. I also tried to use the ClientGlobalContext.js.aspx as a reference but when I do I get an error page (screenshot_4). Any help would be greatly appreciated.

    Thanks, G

    6710.screenshot_5F00_4.jpg2577.screenshot_5F00_2.jpg4643.screenshot_5F00_3.jpg6710.screenshot_5F00_4.jpg

  • ScottDurow Profile Picture
    21 on at

    Could you send me a screenshot of your F12 Network trace when you request your webresource?

  • Community Member Profile Picture
    on at

    Attaching network trace, this one is when client global is referenced, when I take it out, no network trace because it fails

    NetworkData_5F00_ClientGlobal_5F00_IN.txt.zip

  • Verified answer
    ScottDurow Profile Picture
    21 on at

    I've taken a look at this - could you also provide the full unique names of your webresources?

  • Community Member Profile Picture
    on at

    Hi Scott, Thanks for your input it turned out to be a combination of the names and the javascript. it is all fixed now. Thanks again! G

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