Dynamics CRM 2016:自动完成多个字段
Dynamics CRM 2016 : Autocomplete multiple fields
场景如下:
当用户输入邮政编码时,必须显示自动完成,当用户select输入邮政编码时,应自动填写城市和县等其他字段。
关于邮政编码、城市和邮编的信息在一个JSON对象中。
用户点击自动完成列表时是否有事件?
有人知道如何实现吗?
感谢您的帮助
在盒子的 CRM 中,您无法执行您要求的任何操作,但您有 3 种可能性来执行此操作。
1 为您的邮政编码创建一个实体并将您的信息放入其中。在您的表单上创建查找后,我记得以支持的方式执行的唯一方法。
2 在字段的事件发生变化时调用您的方法 js 来自动填充,但是这个字段需要完全扭曲,以便您的脚本获得匹配。
3 这不受支持,但您可以操纵 DOM 并让您的 js 脚本在字段上发生事件时自动填充您的字段。
干杯
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来处理用户的选择。
我刚刚使用 Polshgiant 共享的代码示例测试了您的场景,并按照 Jorge Cunha 的建议在属性上添加了一个 onchange 事件。
不幸的是,我的测试表明,只有击键会触发 onchange 事件:
当我 select 一个自动完成值时,不会触发 onchange。
因此我没有看到这个问题的支持解决方案。
但我需要相同的功能,所以我希望其他人能证明我是错的。
5 月 17 日编辑:
今天的一项新测试显示调用了 onchange 事件,但是
var newValue = Xrm.Page.getControl(control).getValue();
获取键入的值,而不是自动完成的值。
但是
var newValue = Xrm.Page.getControl(control).getAttribute().getValue();
给我自动完成-selected 值。
因此我现在可以使用此功能:-)
场景如下:
当用户输入邮政编码时,必须显示自动完成,当用户select输入邮政编码时,应自动填写城市和县等其他字段。
关于邮政编码、城市和邮编的信息在一个JSON对象中。
用户点击自动完成列表时是否有事件?
有人知道如何实现吗?
感谢您的帮助
在盒子的 CRM 中,您无法执行您要求的任何操作,但您有 3 种可能性来执行此操作。
1 为您的邮政编码创建一个实体并将您的信息放入其中。在您的表单上创建查找后,我记得以支持的方式执行的唯一方法。
2 在字段的事件发生变化时调用您的方法 js 来自动填充,但是这个字段需要完全扭曲,以便您的脚本获得匹配。
3 这不受支持,但您可以操纵 DOM 并让您的 js 脚本在字段上发生事件时自动填充您的字段。
干杯
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来处理用户的选择。
我刚刚使用 Polshgiant 共享的代码示例测试了您的场景,并按照 Jorge Cunha 的建议在属性上添加了一个 onchange 事件。
不幸的是,我的测试表明,只有击键会触发 onchange 事件: 当我 select 一个自动完成值时,不会触发 onchange。
因此我没有看到这个问题的支持解决方案。
但我需要相同的功能,所以我希望其他人能证明我是错的。
5 月 17 日编辑: 今天的一项新测试显示调用了 onchange 事件,但是
var newValue = Xrm.Page.getControl(control).getValue();
获取键入的值,而不是自动完成的值。
但是
var newValue = Xrm.Page.getControl(control).getAttribute().getValue();
给我自动完成-selected 值。
因此我现在可以使用此功能:-)