在表单加载时在警报框中显示parentcontact任务

时间:2015-01-28 12:13:16

标签: javascript dynamics-crm

先决条件: - 在帐户记录中将主要联系人设置为您选择的任何一个联系人 - 对于上述联系人,请创建两个测试任务。实际任务使用帐户表单中的odata保存并迭代以在警报弹出窗口中显示所有名称属性

function dis()
{
var primarycontactid=Xrm.Page.data.entity.attributes.get("primarycontactid").getValue()[0].id;
XrmServiceToolkit.Rest.RetrieveMultiple(
    "TaskSet",
    "?$select=Subject&$filter=RegardingObjectId/Id eq guid'+primarycontactid+'",
    function (results) {
        for (var i = 0; i < results.length; i++) {
            var Description = results[i].Description;
            var Subject = results[i].Subject;
            alert("Description" + Description + " \n subject :" + Subject + "\n success");
        }
    },
    function (error) {
         alert(error.message);
    },
    true
);
}

我在这个代码中哪里出了问题?

2 个答案:

答案 0 :(得分:2)

function retrieveTask(){

var conId=Xrm.Page.data.entity.attributes.get("primarycontactid").getValue()[0].id;
$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/TaskSet?$select=Subject&$filter=RegardingObjectId/Id eq guid'"+conId+"'",
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    async: true,
    success: function (data, textStatus, xhr) {
        var results = data.d.results;
        for (var i = 0; i < results.length; i++) {
            var Subject = results[i].Subject;
            alert(Subject);
        }
    },
    error: function (xhr, textStatus, errorThrown) {
        alert(textStatus + " " + errorThrown);
    }
});

}

检查一下。它会起作用

答案 1 :(得分:1)

您的代码看起来不错,RetrieveMultiple的第二个参数似乎有些错误:

"?$select=Subject&$filter=RegardingObjectId/Id eq guid'+primarycontactid+'",

不应该有最初的?,并且引号看起来在primarycontactid附近搞乱了

"$select=Subject&$filter=RegardingObjectId/Id eq guid'" + primarycontactid + "'",