I am in the process of writing my first HTML webresource, so far I have created the form, embedded it into the projectrelationship entity, I have got the entity id and have also used the odata query designer to query for the data, but how do I used the code
generated by the odata tool in my webresource?
Here is a snapshot of the code:
<HTML><HEAD><BASE>
<META charset=utf-8></HEAD>
<BODY contentEditable=true><FONT size=2 face="Tahoma, Verdana, Arial"></FONT><INPUT onclick="addRow('dataTable')" type=button value="Add Row"> <INPUT onclick="deleteRow('dataTable')" type=button value="Delete Row">
<TABLE id=dataTable width=350 border=1>
<TBODY>
<TR>
<TD><INPUT type=checkbox name=chk></TD>
<TD><INPUT name=txt></TD></TR></TBODY></TABLE>
<SCRIPT language?javascript?>
// Entity Id
alert("Entity Id : " + window.parent.Xrm.Page.data.entity.getId());
RetrievedRecords : function(RegardingObjectId, Description)
{
var query = "/EmailSet?$select=Description, ancon_EmailId, ActivityId&$filter=RegardingObjectId/Id eq guid'" + RegardingObjectId + "' and substringof('" + Description + "', Description)";
ExecuteQuery(query);
}
function ExecuteQuery(ODataQuery)
{
var serverUrl = Xrm.Page.context.getServerUrl();
// Adjust URL for differences between on premise and online
if (serverUrl.match(/V$/))
{
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}
var ODataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + ODataQuery;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: ODataURL,
beforeSend: function (XMLHttpRequest){
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function(data, textStatus, XmlHttpRequest) {
//
// Handle result from successful execution
//
// e.g. data.d.results
alert("There are results");
},
error: function(XmlHttpRequest, textStatus, errorObject) {
//
// Handle result from unsuccessful execution
//
alert("OData Execution Error Occurred");
}
});
}
//
// Error Handler
//
function ErrorHandler(XMLHttpRequest, textStatus, errorObject)
{
alert("Error Occurred : " + textStatus + ": " + JSON.parse(XMLHttpRequest.responseText).error.message.value);
}
After it visually displays the entity id, done for testing purposes, I need it to run the query and return the results to populate a datagrid within the webresource, first issue is getting it to call the query I presume this is done via something like:
RetrievedRecords(window.parent.Xrm.Page.data.entity.getId(), "You")
but then I am a little confused how to write the results to a datagrid?
regards,
Matt