I need to create a HTML webresource to update data in CRM.
I'm using CrmRestKit
to retrieve data.
var fetchxml = [
"<fetch top='50'>",
" <entity name='tisa_qualitycontrolassessment'>",
" <attribute name='tisa_weightrating' />",
" <attribute name='tisa_questionscore' />",
" <attribute name='tisa_qualitycontrolassessmentid' />",
" <attribute name='tisa_questionscorename' />",
" <filter type='and'>",
" <condition attribute='tisa_phonecallid' operator='eq' value='", recordid, "'/>",
" </filter>",
" <link-entity name='tisa_questionqualitycontrolunit' from='tisa_questionqualitycontrolunitid' to='tisa_qualitycontrolunitid' link-type='inner'>",
" <attribute name='tisa_qualitycontrolunitidname' />",
" <attribute name='tisa_questionqualitycontrolunitid' />",
" <attribute name='tisa_name' />",
" <attribute name='tisa_recordcalculation' />",
" <link-entity name='tisa_qualitycontrolunit' from='tisa_qualitycontrolunitid' to='tisa_qualitycontrolunitid' link-type='inner'>",
" <attribute name='tisa_qualitycontrolunitid' />",
" <attribute name='tisa_blockweight' />",
" <attribute name='tisa_name' />",
" </link-entity>",
" </link-entity>",
" </entity>",
"</fetch>",
].join("");
CrmFetchKit.Fetch(fetchxml).then(function(entities){
for(var i = 0, max = entities.length; i < max; i++){
$("assessmentbody").html(i);
}
});
For columns where there is no data(null values) the attribute is not retrieved. There is an option to get all the attributes by fetchXML? Can you please give me an idea about how to get the data (maybe with odata query)?
And how is the best practice to create HTML webresource with option of updating values in a form?
For columns where there is no data(null values) the attribute is not retrieved.
Yes, this is FetchXML expected behavior. This cannot be changed. You can assume it as NULL if the column is missing in your dataset.
how to get the data (maybe with odata query)?
Sure, you can use FetchXML Builder in XrmToolBox. Paste your above query & get the equivalent there.
the best practice to create HTML webresource with option of updating values in a form
I would do update directly in CRM from the HTML webresource field values using service requests. You can compose such queries using CRM REST Builder - 2011 endpoint in your case.
var entity = {};
entity.Name = "Name_updated";
entity.AccountNumber = "123456";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'00000000-0000-0000-0000-000000000000')", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("X-HTTP-Method", "MERGE");
req.onreadystatechange = function() {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 204 || this.status === 1223) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));