MS CRM 2013 - 从 link 实体中检索属性以创建 html 网络资源

MS CRM 2013 - Retrieve attributes from link-entities to create html webresource

我需要创建一个 HTML 网络资源来更新 CRM 中的数据。

我正在使用 CrmRestKit 检索数据。

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);
    }
});

对于没有数据(空值)的列,不会检索属性。有一个选项可以通过 fetchXML 获取所有属性吗?你能告诉我如何获取数据(可能使用 odata 查询)吗?

创建 HTML 带有更新表单值选项的网络资源的最佳做法是什么?

For columns where there is no data(null values) the attribute is not retrieved.

是的,这是 FetchXML 预期的行为。这是无法更改的。如果您的数据集中缺少该列,您可以将其假定为 NULL。

how to get the data (maybe with odata query)?

当然,您可以使用 FetchXML Builder in XrmToolBox。粘贴上面的查询并在那里获得等效项。

the best practice to create HTML webresource with option of updating values in a form

我会使用服务请求从 HTML webresource 字段值直接在 CRM 中进行更新。在您的案例中,您可以使用 CRM REST Builder - 2011 端点来编写此类查询。

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));