我有一个与当前记录n:n关系的子网格。如何将过滤视图添加到功能区“添加现有”按钮
我想添加一个过滤的视图到这个子网格的“Add Existing”按钮。
有什么想法?
(我跟着这篇文章是完全一样的我的要求:http://danielcai.blogspot.com/2011/12/filtered-lookup-for-existing-button-of.html)
我有一个与当前记录n:n关系的子网格。如何将过滤视图添加到功能区“添加现有”按钮
我想添加一个过滤的视图到这个子网格的“Add Existing”按钮。
有什么想法?
(我跟着这篇文章是完全一样的我的要求:http://danielcai.blogspot.com/2011/12/filtered-lookup-for-existing-button-of.html)
首先,你要导出包含的实体类型要过滤的解决方案:
在定制.XML找到RibbonDiffXml节点,并添加以下代码:
<RibbonDiffXml>
<CustomActions />
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</Templates>
<CommandDefinitions />
而在该个CommandDefinitions节点,补充一点:
<CommandDefinitions>
<CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridAssociated">
<EnableRules>
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.AddExisting" />
<DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.CanWriteSelected" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="addExistingCustomFilter" Library="$webresource:new_yourLibrary">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="SelectedControl" />
<CrmParameter Value="PrimaryEntityTypeName" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridStandard">
<EnableRules>
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.AddExisting" />
<DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.CanWriteSelected" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="addExistingCustomFilter" Library="$webresource:new_yourLibrary">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="SelectedControl" />
<CrmParameter Value="PrimaryEntityTypeName" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
代码来自您可以在CRM 2011 SDK发现并已被修改为调用从自定义JavaScript库的自定义功能的XML文件。
然后,在库属性中创建具有上面指定名称的新JS库。
添加第一个泛型函数:
/*****************************************/
/* */
/* Add Custom View To Subgrid */
/* */
/*****************************************/
function addExistingFromSubGridCustom(params) {
var relName = params.gridControl.getParameter("relName"),
roleOrd = params.gridControl.getParameter("roleOrd"),
viewId = "{00000000-0000-0000-0000-000000000001}"; // a dummy view ID
var customView = {
fetchXml: params.fetchXml,
id: viewId,
layoutXml: params.layoutXml,
name: params.name,
recordType: params.gridTypeCode,
Type: 0
};
var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
if (lookupItems && lookupItems.items.length > 0) {
AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, params.gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
}
}
最后,加应由按钮来调用的函数:
function addExistingCustomFilter(gridTypeCode, gridControl, primaryEntityName) {
// Here you can specify for which entity the filter should be applied.
// For example, filter only when you try to add an existing record to a client.
// In the other cases, you will call the default method.
if (primaryEntityName != "client") {
Mscrm.GridRibbonActions.addExistingFromSubGridStandard(gridTypeCode, gridControl);
return;
}
// Add some logic to retrieve information needed to filter your view if you want to
//Update the fetch that will be used by the grid.
var fetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
'<entity name="...">' +
'<attribute name="..." />' +
'<filter type="and">' +
'<condition ... />' +
'</filter>' +
'</entity>' +
'</fetch>';
// Add conditions to your fetch xml dynamically
// Call the generic method with the rights arguments.
addExistingFromSubGridCustom({
gridTypeCode: gridTypeCode,
gridControl: gridControl,
fetchXml: fetch,
name: "My dynamyc custom filtered view!",
layoutXml: '<grid name="" object="' + gridTypeCode + '" jump="all_name" select="1" icon="1" preview="0">' +
// Provide a layout xml ...
'</grid>'
});
}
发布一切,这应该是好!
为了节省一些时间,您可以下载可视化功能区编辑器并跳过一些XML乐趣:) – user1231231412 2012-01-10 14:05:37
@JonC:无法忽略Renaud在下面展示的内容 - 这超出了我所知的任何现有可视化编辑器的功能。 – 2012-01-11 17:39:51
正确。它不能单独做这一切。它可以用来添加一个按钮,设置它的属性,设置它调用的方法,它需要的参数,显示和启用规则。 – user1231231412 2012-01-11 18:06:49