[英]Dynamics CRM 2016 : Autocomplete multiple fields
这是场景:
当用户输入邮政编码时,必须显示自动完成功能,当用户选择邮政编码时,应自动填写其他字段,例如城市和县。
有关邮政编码,城市和邮政编码的信息位于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中,您什么都可以做,而您却有3种可能。
1为您的邮政编码创建一个实体,然后将您的信息放入其中。 在表单上创建查找后,我记得要以受支持的方式进行查找的唯一方法。
2在字段发生事件更改时,调用您的方法js以自动填充,但此字段必须完全写满,以便您的脚本获得匹配。
3不支持此功能,但是您可以操纵DOM并放置js脚本来自动填充字段,并在字段上添加事件。
干杯
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事件来处理用户的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.