简体   繁体   English

使用javaScript访问Dynamics CRM / 365表单中的其他实体属性

[英]Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript

This function buttonBuzz() works inside the Forms of the Entities Account, Contacts and Leads. 该功能buttonBuzz()在实体帐户,联系人和潜在顾客的表单中起作用。 But not in the Opportunity form. 但不是“机会”形式。 Mainly because there is no telephone1 attribute. 主要是因为没有telephone1属性。 There is however a Contact entity added with "Quick View" in a section with a telephonenumber inside. 但是,在其中包含电话号码的部分中,添加了带有“快速查看”的联系人实体。

带有联系快速查看功能的商机表单视图,红色标记

I think it can be accessed with the telephone1 as well just not with Xrm.page 我认为它可以与被访问telephone1如干脆不Xrm.page

Any ideas how i can grab the attribute from inside the "quick view"? 有什么想法可以从“快速视图”内部获取属性吗?

I dont know if the "Quick view" window is a form of an iFrame. 我不知道“快速查看”窗口是否是iFrame的一种形式。 And if it is i have no clue how to access it with the Xrm.Page.getAttribute("telephone1").getValue(); 如果是这样,我不知道如何使用Xrm.Page.getAttribute("telephone1").getValue();来访问它Xrm.Page.getAttribute("telephone1").getValue();

function buttonBuzz(exObj) {
var phoneNumber;

// Here i store the "telephone1" Attribute from the current .page
phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();

if (phoneNumber != null) {      **Sends phonenumber**           } ...

Quick Views display data from a record selected in a lookup field, in this case a Contact. 快速视图显示来自在查找字段中选择的记录(在本例中为联系人)中的数据。 You can query data from related records using the OData endpoint. 您可以使用OData端点从相关记录中查询数据。

You first need to get the Guid of the record selected: 您首先需要获取所选记录的Guid:

var contactId = Xrm.Page.getAttribute("parentcontactid")[0].id || null;

You would then need to send a SDK.REST request, passing parameters for the Id of the record ( contactId ), entityName and the columns : 然后,您需要发送一个SDK.REST请求,并传递记录ID( contactId ), entityNamecolumns

var entityName = "Contact";
var columns = "Address1_Telephone1, FirstName, LastName";    

SDK.REST.retrieveRecord(contactId, entityName, columns, null, function(result) {
    // Success, logic goes here.
    var address1_Telephone1 = result.Address1_Telephone1;
}, function(e) {
    console.error(e.message);
});

As well as your JavaScript file, you would need to include the SDK.REST.js file that is included in the MS CRM SDK download within your Opportunity form libraries. 除了您的JavaScript文件之外,您还需要在Opportunity表单库中包括MS CRM SDK下载中包含的SDK.REST.js文件。

You can pull that field up from the Contact into the Opportunity by creating a Calculated Field, setting it equal to parentcontactid.telephone1 您可以通过创建计算字段并将其设置为parentcontactid.telephone1 ,从“联系人”中将该字段拉入“机会”。

Put the field on the form, and you'll be able to .getAttribute() it like any other Opportunity field (being Calculated, it updates itself whenever the source changes). 将字段放在表单上,​​就可以像其他任何“机会”字段一样将其.getAttribute()进行计算(在计算后,只要源发生更改,它就会自动更新)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM