【问题标题】:Need Help: Account Name on Contact Phone Call需要帮助:联系电话上的帐户名称
【发布时间】:2014-06-16 05:49:00
【问题描述】:

我是 CRM 新手,到目前为止,我已经能够弄清楚一切。我已经阅读了很多帖子和互联网帖子并尝试了它们。我看过一些很多视频。看起来应该很容易。联系人记录具有 ParentCustomerID 和 ParentCustomerName,如果有关联的帐户则持有该帐户。现在我对所需的步骤完全感到困惑。

要求:- 我需要将帐户名称显示在联系人级别的电话表单上并保存在电话表中,以便在电话视图中可见。

我在电话 N:1 中的关系字段 str_companyid(查找)主要实体是具有引用行为的帐户。

我尝试了电话 N:1 关系字段 new_companystring(查找)主要实体是具有引用行为的联系人。我得出的结论是,这不是一个有效的方法。如果不正确,请告诉我。

我需要一个 N:N 代替吗?

我已将 str_companyid 字段添加到表单中。我去了“为联系人创建电话”工作流程。在“创建电话呼叫”步骤中,我添加了动态字段 {Company(Contact)}。保存并发布后;我创建了一个电话,但它没有被填充。

我尝试过不同的 Web Resource JS。我已经在表单属性的加载中添加了 JS。

为什么没有这么简单的事情?我似乎无法让retrieveRecord 工作。我也尝试过 xmlHttpObject 对象,但它返回 0。

有人可以帮助我解决我所缺少的吗?完成此任务的完整步骤是什么? ![我有下面的截图和我正在运行的代码][1]

function PopulateCompanyName() 
{

    //get group GUID
    if (Xrm.Page.getAttribute("to").getValue()[0].id != null) {

        var lookup = Xrm.Page.getAttribute("to").getValue();

        alert(lookup[0].id);
        alert(lookup[0].typename);
        alert(lookup[0].name);

        alert(lookup);

        SDK.JQuery.retrieveRecord(lookup[0].id,
            lookup[0].typename,
            "ParentCustomerID",
            null, 
            function (lookup) {
                Xrm.Page.getAttribute("Company").setValue(lookup[0].str_companyid);
         });
    }

    else {
        Xrm.Page.getAttribute("str_companyid").setValue(null);
    }
}

function GetCompany()

///Get lookup ID

{
alert("I am Here");
 var lookupfield = Xrm.Page.getAttribute("to").getValue();
 if (lookupfield != null && lookupfield [0] != null)
 {
 var householdlookupvalue = lookupfield [0].id;
 }
 else
 {
 var householdlookupvalue = " ";
 }
alert("I am here2");
alert(householdlookupvalue);
}

// Prepare variables for a contact to retrieve.
 var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

// Prepare the SOAP message.
 var xml = ""+
 ""+
 authenticationHeader+
 ""+
 ""+
 "contact"+
 ""+lookupfield [0].id+""+
 ""+
 ""+
 "parentcustomerid"+
 ""+
 ""+
 ""+
 ""+
 "";
alert(xml );
// Prepare the xmlHttpObject and send the request.
 var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
 xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
 xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
 xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
 xHReq.setRequestHeader("Content-Length", xml.length);
 xHReq.send(xml);

// Capture the result.
 var resultXml = xHReq.responseXML;
alert("at results");
var errorCount = resultXml.selectNodes('//error').length;
alert("errorCount " + errorCount); ////////////////////////////////////returns 0; it shouldn't
alert("After the result XML "+resultXml .toString() + " ::::");

// Check for errors.
 var errorCount = resultXml.selectNodes('//error').length;
 if (errorCount != 0)
 {

}
 // Display the retrieved value.
 else
 {

//Create an array to set as the DataValue for the lookup control.
 var lookupData = new Array();

//Create an Object add to the array.
 var lookupItem= new Object();

//Set the id, typename, and name properties to the object.
 lookupItem.id = resultXml.selectSingleNode("//q1:parentcustomerid").nodeTypedValue;
 lookupItem.entityType = 'account';
 lookupItem.name = resultXml.selectSingleNode("//q1:parentcustomerid").getAttribute("name");
 // Add the object to the array.
 lookupData[0] = lookupItem;
alert(lookupitem.name)
// Set the value of the lookup field to the value of the array.
 Xrm.Page.getAttribute("str_companyid").setValue(lookupData);
 }


    var contact = new Array();
    contact = Xrm.Page.getAttribute("to").getValue();
alert("I am here");
alert(contact);
    if (contact == null || contact[0].entityType != "contact" || contact.length > 1) {
        return;
    }
alert("inside if")
    var serverUrl = Xrm.Page.context.getClientUrl();
    var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=ParentCustomerId&$filter=ContactId eq guid'" + contact[0].id + "'";

    var retrieveReq = new XMLHttpRequest();
    retrieveReq.open("GET", oDataSelect, false);
    retrieveReq.setRequestHeader("Accept", "application/json");
    retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    retrieveReq.onreadystatechange = function () {
        GetContactData(this);
    };
    retrieveReq.send();
}

【问题讨论】:

    标签: dynamics-crm-2011


    【解决方案1】:

    我在其他论坛上回复过,但我在这里发帖作为参考并提供更多技术细节。 phonecall 实体的to 属性是partylist 类型,这意味着它可以处理来自不同实体的多个记录。在您的情况下,如果联系人在 to 字段内,您希望获取父帐户(字段 parentcustomerid)。

    您的第一个代码包含相同的拼写错误并使用 msdn Retrieve 示例,第二个代码使用 CRM 4.0 端点,它们在 CRM 2011 中仍受支持,但最好避免使用它们,这样您就可以使用 REST 端点而不是 SOAP 端点.

    您的情况下的工作代码可以是:

    function setToParentAccount() {
        // set only if to Field (Recipient) has 1 record and is a contact
        if (Xrm.Page.getAttribute("to").getValue() != null) {
            var recipient = Xrm.Page.getAttribute("to").getValue();
            if (recipient.length == 1 && recipient[0].entityType == "contact") {
    
                var contactId = recipient[0].id;
                var serverUrl;
                if (Xrm.Page.context.getClientUrl !== undefined) {
                    serverUrl = Xrm.Page.context.getClientUrl();
                } else {
                    serverUrl = Xrm.Page.context.getServerUrl();
                }
    
                var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc"; 
                var contactRequest = new XMLHttpRequest();
                contactRequest.open("GET", ODataPath + "/ContactSet(guid'" + contactId + "')", false); 
                contactRequest.setRequestHeader("Accept", "application/json"); 
                contactRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    
                contactRequest.send();
                if (contactRequest.status === 200) {
                    var retrievedContact = JSON.parse(contactRequest.responseText).d;
                    var parentAccount = retrievedContact.ParentCustomerId;
    
                    if (parentAccount.Id != null && parentAccount.LogicalName == "account") {
                        var newParentAccount = new Array();
                        newParentAccount[0] = new Object();
                        newParentAccount[0].id = parentAccount.Id;
                        newParentAccount[0].name = parentAccount.Name;
                        newParentAccount[0].entityType = parentAccount.LogicalName;
                        Xrm.Page.getAttribute("str_companyid").setValue(newParentAccount);
                    } else {
                        Xrm.Page.getAttribute("str_companyid").setValue(null);
                    }
                } else {
                        alert("error");
                }
            } else {
                Xrm.Page.getAttribute("str_companyid").setValue(null);
            }
        }
    }
    

    to 字段的 OnLoad 事件和 OnChange 事件中调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多