Javascript, HTML5 and Dynamics CRM

Associate
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
I am looking at HTML5 and javascript for Dynamics CRM as I am just starting with this I have created a basic form with a button and a combobox, I want to click the button and it populate the combobox with values.

All works well when the code is included in the form, but if I split the code off from the form when the button is clicked nothing happens.

I can tell the button fires the code correctly as I can put an alert in the function and that fires correctly, I think it is how it refers to the control on the form that is incorrect, so can anyone point me to an example doing the above?

regards,

Matt
 
Associate
OP
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
Javascript file

Code:
function populateone(s2) {
    
    var s2 = document.getElementById(s2);
    s2.innerHTML = "";
    var optionArray = ["|", "mustang|Mustang", "shelby|Shelby"];

    for (var option in optionArray) {
        var pair = optionArray[option].split("|");
        var newOption = document.createElement("option");
        newOption.value = pair[0];
        newOption.innerHTML = pair[1];
        s2.options.add(newOption);
    }
}

html file

Code:
<!DOCTYPE HTML>
<html> 
<head> 
<title>Fetch 2011 JavaScript Example</title> 
<link rel="stylesheet" type="text/css" href="/_common/styles/theme.css.aspx" /> 
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css.aspx" /> 
<link rel="stylesheet" type="text/css" href="/_common/styles/fonts.css.aspx" /> 
<link rel="stylesheet" type="text/css" href="/_common/styles/Dialogs.css.aspx" />

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

</script>

</head> 
<body> 
<table style="width: 100%; height: 100%;" cellspacing="0" cellpadding="0" border="0"> 
<tr> 
<td class="ms-crm-Dialog-Header" id="tdDialogHeader"> 
<div id="divTitle" class="ms-crm-Dialog-Header-Title">Executing Fetch from JavaScript in CRM 2011</div>
<div id="divInstructions" class="ms-crm-Dialog-Header-Desc">Enter some FetchXML to be executed against your CRM environment</div> 
</td> 
</tr> 
<tr> 
<td style="height: 100%;"> 
<div class="ms-crm-Dialog-Main" style="padding: 14px;"> 
<label>Fetch Command</label><br /> 
<textarea id="txtFetch" rows="8" width="100%" cols="100" ></textarea><br /> 
<!--<input type="Submit" value="Fetch" onClick="javascript:executeFetchCommand();" style="width:100px;height:24px;">--> 
<input type="Submit" value="Fetch" onClick="populateone('combo')" style="width:100px;height:24px;"> 
<div id='dvData' style="width: 100%; height: 100%;"></div> 
</div> 
</td> 
</tr> 
<tr> 
<td class="ms-crm-Dialog-Footer" id="tdDialogFooter"> 
<table cellspacing="0" cellpadding="0"> 
<tr>
 <select id="combo" name ="combo">
    <!--<option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>-->

</select>
<td width="100%"></td>


<td></td>
<td>&nbsp;<button onclick="window.close();" class="ms-crm-Button">Done</button></td> 
</tr> 
</table> 
</td> 
</tr> 
</table>

</body> 
</html>

The code is borrowed from another website and when the java is added to the html file all is well, when it is moved out to the file it does nothing in ie11.


regards,

Matt
 
Associate
Joined
1 May 2007
Posts
1,901
Location
London
The code is working fine for me in IE11.

How are you running the code - through a web server or just as local files?

When you have the js in the separate file (as_/scripts/FetchUtil.js) does that directory and file exist?

Are you getting any errors in the your console (F12)?
 
Associate
OP
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
Sorted it now, helps if ehen uploading the file to crm you check that after you have uploaded it, it actually has uploaded it!!!!

Thanks for your help.

regards


Matt
 
Associate
Joined
10 Nov 2013
Posts
1,808
Is the populateone function in the FetchUtil.js file? Is that file even being loaded when you load the page?

Stick an 'alert("test");' at the top of FetchUtil.js to be sure.

Where is the fetchutil file being hosted from? If you can access it at http://server/as_/scripts/FetchUtil.js then your src attribute should be "/as_/scripts/FetchUtil.js"


EDIT: too slow!
 
Last edited:
Back
Top Bottom