1

我在触发 OnLoad 的服务活动表单上附加了一些 Javascript。它检索与服务案例(与服务活动相关)关联的 TechId,并尝试将服务活动的资源默认设置为该用户。

未解析资源的屏幕截图

正如您在上面的屏幕截图中看到的那样,它将正确的“名称”插入到“资源”字段中,但由于图标“已损坏”,它似乎无法正确解析它。如果我删除它并手动添加相同的用户,一切正常。如果我尝试按图像中的样子保存此活动,则会生成一个错误,指出调度引擎有问题。

我用来设置这个值的代码是;

function SetTechId()
{
if (Xrm.Page.getAttribute("resources").getValue() == null)
{
    if (Xrm.Page.getAttribute("regardingobjectid").getValue() != null)
    {
        var caseId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;

        var endPoint = getODataEndPoint();
        var odataSelect = endPoint + "/IncidentSet?$select=new_new_fieldtechs_incident/OwnerId,new_new_fieldtechs_incident/OwningUser&$expand=new_new_fieldtechs_incident&$filter=IncidentId eq guid'" +  caseId + "'";

        $.ajax({
               type: "GET",
               contentType: "application/json; charset=utf-8",
               datatype: "json",
               url: odataSelect,
               beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
               success: function (data, textStatus, XmlHttpRequest) 
                   {
                        if (data.d != null)
                        {
                            var fieldTech = data.d.results[0];
                            var ownerId = fieldTech.new_new_fieldtechs_incident.OwnerId;

                            //because the resources field in the service activity is a partylist, we need to treat this differently
                            var partylist = new Array();
                            partylist[0] = new Object();
                            partylist[0].id = ownerId.Id; //Guid (i.e., Guid of User or Contact etc)
                            partylist[0].name = ownerId.Name; //Name (i.e., Name of User or Contact etc)
                            partylist[0].entityType = "account"; //entity schema name of account or contact

                            Xrm.Page.getAttribute("resources").setValue(partylist);
                        }
                   },
               error: function (XmlHttpRequest, textStatus, errorThrown) { }
        });
    }
}
}

function getODataEndPoint() {
return Xrm.Page.context.prependOrgName("/xrmservices/2011/OrganizationData.svc"); 
};
4

1 回答 1

4

“托尼·哈雷”真的是一个account还是一个systemuser

partylist[0].entityType = "account"; //entity schema name of account or contact
于 2012-06-29T10:39:15.953 回答