MSCRM4.0实体所有权组织更改为用户(mscrm update entity ownership)

来源:互联网 发布:win7apache mysql php 编辑:程序博客网 时间:2024/06/13 03:02
 

原由:由于用户新建实体时选择了所有权属于:组织,导致角色权限建立的时候只能是组织级别的,所以需要更改实体的所有权,MSCRM4.0测试通过没有任何问题

方法一:最老实的方法,将该实体删除后重新建立,但是这个方法值适用于那种实体字段比较少的,对于比较多Field的实体,重新建立就特别的麻烦,所以我们打算用方法二来处理

方法二:我们都是微软的MSCRM软件内的每个实体在数据库中保存都是以XML的形式存储的,所以,我们可以将该实体的XML导出,然后对该实体的XML进行分析,最好的方法是自己建立一个组织级别的实体,然后再建立一个用户级别的实体,对比两个实体的XML

首先,请备份数据库

step 1:
导出该实体
找到ownership对应的节点,这个节点在Entity里面,节点为OwnershipTypeMask。
<OwnershipTypeMask>OrgOwned</OwnershipTypeMask>
我们将该节点的value更改为UserOwned
<OwnershipTypeMask>UserOwned</OwnershipTypeMask>

step 2:
找到entity节点下面的attributes节点
下面有一个节点名为OrganizationId

          <attribute PhysicalName="OrganizationId">              <Type>lookup</Type>              <ValidForReadApi>1</ValidForReadApi>              <ReferencedEntityObjectTypeCode>1019</ReferencedEntityObjectTypeCode>              <AttributeTypeId>00000000-0000-0000-00aa-110000000031</AttributeTypeId>              <Descriptions>                <Description description="组织的唯一标识符" languagecode="2052" />              </Descriptions>              <ImeMode>auto</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <LookupTypes />              <displaynames>                <displayname description="组织 ID" languagecode="2052" />              </displaynames>            </attribute>


 

将此节点删除
copy下面的节点来替换这个节点

           

            <attribute PhysicalName="OwnerId">              <Type>owner</Type>              <IsNullable>0</IsNullable>              <ValidForCreateApi>1</ValidForCreateApi>              <ValidForReadApi>1</ValidForReadApi>              <IsLogical>1</IsLogical>              <AttributeTypeId>00000000-0000-0000-00aa-110000000035</AttributeTypeId>              <DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>              <Descriptions>                <Description description="负责人 ID" languagecode="2052" />              </Descriptions>              <ImeMode>auto</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <LookupStyle>single</LookupStyle>              <LookupTypes />              <displaynames>                <displayname description="负责人" languagecode="2052" />              </displaynames>            </attribute>            <attribute PhysicalName="OwnerIdDsc">              <Type>int</Type>              <IsNullable>0</IsNullable>              <ValidForReadApi>1</ValidForReadApi>              <IsLogical>1</IsLogical>              <AttributeTypeId>00000000-0000-0000-00aa-110000000019</AttributeTypeId>              <AttributeOf>OwnerId</AttributeOf>              <XmlAbbreviation>dsc</XmlAbbreviation>              <ImeMode>disabled</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <MinValue>-2147483648</MinValue>              <MaxValue>2147483647</MaxValue>            </attribute>            <attribute PhysicalName="OwnerIdName">              <Type>nvarchar</Type>              <Length>320</Length>              <IsNullable>0</IsNullable>              <ValidForReadApi>1</ValidForReadApi>              <IsLogical>1</IsLogical>              <AttributeTypeId>00000000-0000-0000-00aa-11000000001e</AttributeTypeId>              <AttributeOf>OwnerId</AttributeOf>              <XmlAbbreviation>name</XmlAbbreviation>              <IsSortAttribute>1</IsSortAttribute>              <Descriptions>                <Description description="负责人的名称" languagecode="2052" />              </Descriptions>              <ImeMode>auto</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format>text</Format>              <MaxLength>100</MaxLength>            </attribute>            <attribute PhysicalName="OwnerIdType">              <Type>int</Type>              <ValidForCreateApi>1</ValidForCreateApi>              <ValidForReadApi>1</ValidForReadApi>              <IsLogical>1</IsLogical>              <AttributeTypeId>00000000-0000-0000-00aa-110000000019</AttributeTypeId>              <DisplayMask>ObjectTypeCode</DisplayMask>              <AttributeOf>OwnerId</AttributeOf>              <XmlAbbreviation>type</XmlAbbreviation>              <Descriptions>                <Description description="负责人 ID 类型" languagecode="2052" />              </Descriptions>              <ImeMode>disabled</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <MinValue>-2147483648</MinValue>              <MaxValue>2147483647</MaxValue>            </attribute>            <attribute PhysicalName="OwningBusinessUnit">              <Type>lookup</Type>              <ValidForReadApi>1</ValidForReadApi>              <ReferencedEntityObjectTypeCode>10</ReferencedEntityObjectTypeCode>              <AttributeTypeId>00000000-0000-0000-00aa-110000000031</AttributeTypeId>              <Descriptions>                <Description description="负责记录的业务部门的唯一标识符" languagecode="2052" />              </Descriptions>              <ImeMode>auto</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <LookupStyle>single</LookupStyle>              <LookupTypes />              <displaynames>                <displayname description="负责的业务部门" languagecode="2052" />              </displaynames>            </attribute>            <attribute PhysicalName="OwningUser">              <Type>lookup</Type>              <ValidForCreateApi>1</ValidForCreateApi>              <ValidForUpdateApi>1</ValidForUpdateApi>              <ValidForReadApi>1</ValidForReadApi>              <ReferencedEntityObjectTypeCode>8</ReferencedEntityObjectTypeCode>              <AttributeTypeId>00000000-0000-0000-00aa-110000000031</AttributeTypeId>              <AggregateOf>OwnerId</AggregateOf>              <Descriptions>                <Description description="负责记录的用户的唯一标识符" languagecode="2052" />              </Descriptions>              <ImeMode>auto</ImeMode>              <RequiredLevel>none</RequiredLevel>              <Format />              <LookupStyle>single</LookupStyle>              <LookupTypes />            </attribute>



step 3:我们继续往下看,找到FormXML节点,然后打开,找到我们UI上对应已经放上去的Field,然后随便找一个空的cell将以下的代码放到里面去
 如果找不到空的cell,那就自己新建一个row,然后再新建cell,对应的放到里面去就可以了。


 

                            <labels>                              <label description="负责人" languagecode="2052" />                            </labels>                            <control id="ownerid" classid="{270BD3DB-D9AF-4782-9025-509E298DEC0A}" datafieldname="ownerid" />



step 4:继续往下找,找到一个属性为EntityRelationships的节点,打开之后看到的就是跟这个实体有关的所有的1:N,N:1或者N:N的关系
 其他的不要看,我们只需要找到EntityRelationship Name="organization_new_xtytbtcpthjjpt"这个Name是organization开头的就可以了,这个name由两部分组成
 前面的是组织实体,后面的是你自己的实体名称,下面删除这个relationship,然后将以下的代码copy进去。记得copy完之后要将下面黄色部分的字段改成你自己的实体名称。

   

<EntityRelationship Name="user_new_xtytbtcpthjjpt">      <EntityRelationshipType>OneToMany</EntityRelationshipType>      <ReferencingEntityName>new_xtytbtcpthjjpt</ReferencingEntityName>      <ReferencedEntityName>SystemUser</ReferencedEntityName>      <ReferencingAttributeName>owninguser</ReferencingAttributeName>      <RelationshipDescription>        <Descriptions>          <Description description="负责记录的用户的唯一标识符" languagecode="2052" />        </Descriptions>      </RelationshipDescription>      <field name="owninguser" requiredlevel="none" imemode="auto" lookupstyle="single" lookupbrowse="0">        <displaynames />      </field>    </EntityRelationship>    <EntityRelationship Name="business_unit_new_xtytbtcpthjjpt">      <EntityRelationshipType>OneToMany</EntityRelationshipType>      <ReferencingEntityName>new_xtytbtcpthjjpt</ReferencingEntityName>      <ReferencedEntityName>BusinessUnit</ReferencedEntityName>      <ReferencingAttributeName>owningbusinessunit</ReferencingAttributeName>      <RelationshipDescription>        <Descriptions>          <Description description="负责记录的业务部门的唯一标识符" languagecode="2052" />        </Descriptions>      </RelationshipDescription>      <field name="owningbusinessunit" requiredlevel="none" imemode="auto" lookupstyle="single" lookupbrowse="0">        <displaynames>          <displayname description="负责的业务部门" languagecode="2052" />        </displaynames>      </field> </EntityRelationship>


step 5:删除CRM中你刚导出的这个实体。
step 6:删除之后将你修改之后的XML导入到CRM中,发布,然后看看是否完成


整个修改的过程大概就是如此,特别需要注意的地方是,如果你的实体又关联关系的其他自己定义的实体的话,建议你导出的时候也一起导出。这样就可以方便你导入之后就不需要再对应的建立实体之间的关系。系统自带的实体关系是不需要的,可以不导出。导出后如果关系过多的话看清楚了再改,以免改错。

还有一个要再次强调,修改之前要备份啊。。。