动态CRM 2016年自动完成多个领域
下面是这种情况:动态CRM 2016年自动完成多个领域
当用户输入一个邮政编码,自动完成必须显示,当用户选择一个邮政编码,其他领域,如城市和该县应自动填写。
有关邮政编码,城市和邮政编码的信息位于JSON对象中。
当用户点击自动完成列表时是否有一个事件?
有谁知道如何做到这一点?
感谢您的帮助
CRM 2016最近添加,您可以使用字符串字段,让你做你想要什么做一个按键事件(在移动设备上不工作,虽然)。这里的SDK's example:
/* 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 event来处理用户的选择。
从你没有什么做你所要求的盒子的CRM,但你有3个可能做到这一点。
1为您的邮政编码创建一个实体并将您的信息放入其中。在表单上创建查找后,我记得在支持的方式上做的唯一方法。
2关于字段的事件更改,请调用您的方法js自动填充,但是这个字段需要被完整地调整,以便您的脚本获得匹配。
3这不受支持,但您可以操纵DOM并将您的js脚本自动填充字段以显示该字段上的事件。
干杯
感谢豪尔赫,如果我理解(方法2),我会得到场(邮政编码)与onchange事件的价值,找到匹配在我的数组中,然后填充其他字段? – bidou88
是的,这正是你所说的。 onchange事件将触发你的函数来获得匹配,你可以自动填充你的结果。 –
我刚刚使用代码示例测试了您的场景,Polshgiant在Jorge Cunha建议的属性上共享并添加了onchange事件。
不幸的是,我的测试显示,只有击键触发onchange事件: 当我选择自动完成值时,onchange不会被触发。
因此,我看不到此问题的支持解决方案。
但我需要相同的功能,所以我希望别人能证明我是错的。
编辑5月17日:今天 一个新的测试表明,onchange事件被调用,但
var newValue = Xrm.Page.getControl(control).getValue();
得到键入的值,而不是自动完成的值。
然而
var newValue = Xrm.Page.getControl(control).getAttribute().getValue();
给我的自动完成功能选择的值。
因此我现在可以使用这个功能:-)
感谢您的回答。我忘了提及我正在使用这个脚本。当用户点击自动完成列表中的项目时是否有事件发生?为了获得点击项目并填写其他字段? – bidou88
@ bidou88看到我的更新 – Polshgiant