Dynamics CRM 2016:自动完成多个字段

Dynamics CRM 2016 : Autocomplete multiple fields

本文关键字:字段 CRM 2016 Dynamics      更新时间:2023-09-26

以下是场景:

当用户输入邮政编码时,必须显示自动填写项,当用户选择邮政编码后,其他字段(如城市和县)应自动填写。

关于邮政编码、城市和邮政编码的信息在一个JSON对象中。

用户单击自动完成列表时是否发生事件?

有人知道如何做到这一点吗?

感谢您的帮助

我刚刚使用Polshgiant共享的代码示例测试了您的场景,并按照Jorge Cunha的建议在属性上添加了一个onchange事件。

不幸的是,我的测试显示,只有按键才会触发onchange事件:当我选择一个自动完成值时,onchange不会被激发。

因此,我认为这个问题没有得到支持的解决方案。

但我需要同样的功能,所以我希望其他人能证明我错了。

编辑5月17日:今天的一个新测试显示onchange事件被调用,但是

var newValue = Xrm.Page.getControl(control).getValue(); 

获取键入的值,而不是自动完成的值。

然而

var newValue = Xrm.Page.getControl(control).getAttribute().getValue();

给我自动完成选定的值。

因此,我现在可以使用此功能:-)

CRM 2016最近添加了一个按键事件,您可以将其用于字符串字段,这些字段允许您完全执行您想要执行的操作(但在移动设备上不起作用)。以下是SDK的示例:

/* Sample JavaScript code to demonstrate the auto-completion feature.
   This sample configures the auto-complete feature for the "Account Name"
   field in the account form. */
function suggestAccounts() {
    // List of sample account names to suggest
    accounts = [
  { name: 'A. Datum Corporation', code: 'A01' },
  { name: 'Adventure Works Cycles', code: 'A02' },
  { name: 'Alpine Ski House', code: 'A03' },
  { name: 'Bellows College', code: 'A04' },
  { name: 'Best For You Organics Company', code: 'A05' },
  { name: 'Blue Yonder Airlines', code: 'A06' },
  { name: 'City Power & Light', code: 'A07' },
  { name: 'Coho Vineyard', code: 'A08' },
  { name: 'Coho Winery', code: 'A09' },
  { name: 'Coho Vineyard & Winery', code: 'A10' },
  { name: 'Contoso, Ltd.', code: 'A11' },
  { name: 'Proseware, Inc.', code: 'A30' },
  { name: 'Relecloud', code: 'A31' },
  { name: 'School of Fine Art', code: 'A32' },
  { name: 'Southridge Video', code: 'A33' },
  { name: 'Tailspin Toys', code: 'A34' },
  { name: 'Trey Research', code: 'A35' },
  { name: 'The Phone Company', code: 'A36' },
  { name: 'VanArsdel, Ltd.', code: 'A37' },
  { name: 'Wide World Importers', code: 'A38' },
  { name: '​Wingtip Toys', code: 'A39' },
  { name: 'Woodgrove Bank', code: 'A40' }    
    ];
    var keyPressFcn = function (ext) {
        try {
            var userInput = Xrm.Page.getControl("name").getValue();
            resultSet = {
                results: new Array(),
                commands: {
                    id: "sp_commands",
                    label: "Learn More",
                    action: function () {
                        // Specify what you want to do when the user
                        // clicks the "Learn More" link at the bottom
                        // of the auto-completion list.
                        // For this sample, we are just opening a page
                        // that provides information on working with
                        // accounts in CRM.
                        window.open("http://www.microsoft.com/en-us/dynamics/crm-customer-center/create-or-edit-an-account.aspx");
                    }
                }
            };
            var userInputLowerCase = userInput.toLowerCase();
            for (i = 0; i < accounts.length; i++) {
                if (userInputLowerCase === accounts[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
                    resultSet.results.push({
                        id: i,
                        fields: [accounts[i].name]
                    });
                }
                if (resultSet.results.length >= 10) break;
            }
            if (resultSet.results.length > 0) {
                ext.getEventSource().showAutoComplete(resultSet);
            } else {
                ext.getEventSource().hideAutoComplete();
            }
        } catch (e) {
            // Handle any exceptions. In the sample code,
            // we are just displaying the exception, if any.
            console.log(e);
        }
    };
    Xrm.Page.getControl("name").addOnKeyPress(keyPressFcn);    
}

然后,您可以使用addOnChange事件来处理用户的选择。

从盒子的CRM中,你没有任何事情可以按照你的要求做,但你有三种可能性可以做到。

1为您的邮政编码创建一个实体,并将您的信息放在里面。在你的表单上创建查找后,我记得唯一的方法是使用支持的方式。

2在字段发生事件更改时,调用您的方法js来自动填充,但在此情况下,字段需要完全扭曲,以便编写脚本来获得匹配。

3这是不受支持的,但您可以操作DOM并使用js脚本在字段上自动填充事件。

干杯