简体   繁体   English

Dynamics CRM 2011:添加非实体表单字段

[英]Dynamics CRM 2011: Adding non-entity form fields

I keep on finding myself wanting to add fields to CRM forms that don't actually represent physical fields on the entity. 我一直在发现自己想要将字段添加到实际上并不代表实体上的物理字段的CRM表单。 I want these fields to be sent in the Update message, for the benefit of my Plugins... 我希望在更新消息中发送这些字段,以利于我的插件...

For example, imagine something like the out-of-the-box contact/address functionality. 例如,想象一下开箱即用的联系人/地址功能。 The main contact address is exposed as a set of fields on the Contact form. 主要联系地址在“联系人”表单中显示为一组字段。 However, in actual fact there is some magic going on behind the scenes that causes an Address record to be created for the Contact containing the address details. 然而,事实上,在幕后有一些神奇的事情会导致为包含地址详细信息的联系人创建地址记录。 I don't actually want to reproduce this, but it's a fair example... 我实际上并不想重现这一点,但这是一个公平的例子......

Now, I know how to write a plugin that takes the address fields entered in the Create/Update message, and actually writes them into an Address object instead. 现在,我知道如何编写一个插件,该插件接受在Create / Update消息中输入的地址字段,并实际将它们写入Address对象。 That is simple enough. 这很简单。 It seems the hard part is convincing CRM to display fields on the form for the user to enter the address data. 似乎难以说服CRM在表单上显示字段以供用户输入地址数据。

The only way I can see to do this is to create "fake" fields in the Contact-equivilent form, so that the form editor allows me to add the fields to the dialog. 我能看到的唯一方法是在Contact-equivilent表单中创建“假”字段,以便表单编辑器允许我将字段添加到对话框中。 Then I have to filter these attributes out in a plugin, so the fake fields don't actually get written to the DB. 然后我必须在插件中过滤掉这些属性,因此伪字段实际上不会写入数据库。

This would work, but involves filling the DB schema with fake columns that will (or should ) never have any data in them. 这可以工作,但涉及用假列填充数据库模式,这些列将(或应该 )永远不会有任何数据。 This makes future cusomisation of the system more confusing, as there are decoy fields called "DON'T USE - Address1" knocking around in all the GUIs. 这使得系统的未来结合更加混乱,因为在所有GUI中存在称为“不使用 - 地址1”的诱饵字段。 The problem gets worse when I need a fake Lookup field - this involves creating a fake relationship. 当我需要一个假的Lookup字段时问题变得更糟 - 这涉及创建一个假的关系。

So: Is there a way to achieve the same thing without dumping fake garbage in the database schema? 那么:有没有办法在不丢弃数据库模式中的假垃圾的情况下实现同样的目的?

Is there, perhaps, some way to create a form field for an arbitary attribute in Javascript on the form, such that the Attributes will be included in an Update message? 或许,某种方法可以在表单上的Javascript中为任意属性创建表单字段,以便属性将包含在更新消息中?

Sure, I realise I could IFrame or Silverlight something up to cater for this, but I'd rather use the genuine CRM form fields, and handle the data in the Update/Create message plugin hook. 当然,我意识到我可以使用IFrame或Silverlight来满足这一要求,但我宁愿使用真正的CRM表单字段,并处理更新/创建消息插件钩子中的数据。

Unfortunately, you have already mentioned the two options that I can think of: fake fields or custom IFrames. 不幸的是,您已经提到了我能想到的两个选项:假字段或自定义IFrame。

I know it feels "dirty" but I actually haven't had much trouble doing the fake fields thing. 我知道这感觉“很脏”,但实际上我做假场的事情并没有太多麻烦。 Standardized naming conventions are your friend. 标准化的命名约定是你的朋友。 I prefer fake fields over IFrames because users can still query and filter them in Advanced Find, reports, views, etc. 我更喜欢伪领域而不是IFrame,因为用户仍然可以在高级查找,报告,视图等中查询和过滤它们。

Just make sure they are readonly and make sure your plugins don't swallow exceptions - you want exceptions to bubble up and cancel the transaction instead of the possibility of the main record getting updated without the children. 只要确保它们是只读的,并确保你的插件不会吞下异常 - 你想要例外来冒泡并取消交易,而不是主要记录在没有孩子的情况下更新的可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM