Microsoft Dynamics CRM4.0学习笔记(二)

来源:互联网 发布:优化驱动器有什么用 编辑:程序博客网 时间:2024/05/22 03:40

Microsoft Dynamics CRM4.0学习笔记(二)

简介:本文将讲述多对多关系和映射与Lookup类型以及Onload和数据库触发器的结合运用

               本文将以一个功能点例子,图文结合的方式讲述;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

               需求简述:

               就是一个精准广告合同和精准广告执行单,它们是主从关系(重点记住这点和理解)

               在精准广告合同和精准广告执行单表单中添加一个字段(实际投放客户<Lookup>),

               当建立合同的执行单时,将合同的实际投放客户信息映射过去,但是他们彼此可以保存

               自己的实际投放客户,互不影响;以及不同合同和部分用户权限的控制;

----------------------------------------------------------------------------------------------------------------------------------------------

                详细需求:

                在CPC精准广告合同中添加字段“实际投放客户”
                设置同普通广告合同中的“实际投放客户“一致:
              (1)合同中添加了实际投放客户后,然后建立的执行单中可以自动带入实际投放客户;反之,如先建执行单,

                再在合同中添加实际投放客户,则执行单中不同步实际投放客户
              (2)修改执行单中的实际投放客户,不影响合同中的实际投放客户;同样修改合同中的实际投放客户,

               也不影响已有实际投放客户的执行单
              (3)在审核完毕状态前,媒介、一审、二审均有权限修改
              (4)审核完毕及以后的状态,只有一审、二审有修改的权限

----------------------------------------------------------------------------------------------------------------------------------------------

效果图如下:

----------------------------------------------------------------------------------------------------------------------------------------------

解决方案:

-----------------------精准广告合同-----------------------
1.建立两个字段([实际投放客户]一个带display的,一个不带<nvarchar>),
  建立一个多对多关系(直客客户)

2.表单增加字段(实际投放客户[不带display])

3.项目中精准广告合同的Onload.js中增加JS控制Lookup的JS代码块

4.数据库中的触发器添加相对应的截取转换插入代码块

-----------------------精准广告执行单-----------------------
1.建立两个字段([实际投放客户]一个带display的,一个不带<nvarchar>),
  建立一个多对多关系(直客客户)

2.表单增加字段(实际投放客户[不带display])

3.项目中精准广告合同的Onload.js中增加JS控制Lookup的JS代码块

4.数据库中的触发器添加相对应的截取转换插入代码块

5.在精准广告执行单的自定义实体中的一对多关系中,找到【精准广告执行单】关系
  建立【实际投放客户】映射关系

----------------------------------------------------------------------------------------------------------------------------------------------

 精准广告合同:

 建立两个字段([实际投放客户]一个带display的,一个不带<nvarchar>),
 建立一个多对多关系(直客客户)

 表单增加字段(实际投放客户[不带display])

 

 

----------------------------------------------------------------------------------------------------------------------------------------------

 项目中精准广告合同的Onload.js中增加JS控制Lookup的JS代码块(或者在表单属性的Onload事件中添加也一样)

 

    //彭振&钟雨 20151026 在CPC精准广告合同中添加字段“实际投放客户”    if (abname.indexOf('AUTO') >= 0) {        if (UserRoles.indexOf('汽核') >= 0 || UserRoles.indexOf('合员') >= 0 || UserRoles.indexOf('系员') >= 0 || (new_tacontract_lateststatus.DataValue == 1 && UserRoles.indexOf('销理') >= 0)) {            document.getElementById('new_tacontract_actdirectaccount').fetchxml = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\"><entity name=\"new_directaccount\"><attribute name=\"new_name\"/><order attribute=\"new_name\" descending=\"false\"/><filter type=\"and\"><condition attribute=\"new_name\" operator=\"like\" value=\"%%\"/><condition attribute=\"new_directaccount_businessline\" operator=\"like\" value=\"%AU%\"/><condition attribute=\"statecode\" operator=\"eq\" value=\"0\"/></filter></entity></fetch>";            try {                var mylookupbrand = new MyLookupControl("new_tacontract_actdirectaccount", "直客客户", "new_name", "/CRM/readonly.aspx?objTypeCode=10195&id=");            } catch (e) { }        } else {            new_tacontract_actdirectaccount.Disabled = true;        }    } else {        new_tacontract_actdirectaccount.Disabled = true;    }

----------------------------------------------------------------------------------------------------------------------------------------------

 数据库中的触发器添加相对应的截取转换插入代码块

 

--实际使用客户字段格式化 2015-10-26 16:48:51 彭振IF(update(new_tacontract_actdirectaccount))begindeclare @tmptb table(idx int identity primary key, objectId uniqueidentifier,dirs nvarchar(max))declare @objectId uniqueidentifier,@breakindex int,@tmpstr nvarchar(max);insert into @tmptbselect New_tacontractId,New_tacontract_actdirectaccount from INSERTED ideclare @idx int;set @idx = 1;while(exists(select idx from @tmptb t where t.idx = @idx))begindeclare @dirs nvarchar(max), @dirsdisplay nvarchar(max);select @objectId = objectId,@dirs = dirs + '[;]' from @tmptb t where t.idx = @idx;set @dirsdisplay = null;delete ds from new_tacontract_directaccount_rrBase ds where ds.new_tacontractid = @objectIdset @breakindex = 0;while(len(@dirs) > 0)begindeclare @dirId uniqueidentifier;set @tmpstr = left(@dirs, charindex('[;]',@dirs)-1)set @dirId = left(@tmpstr, charindex('[:]',@tmpstr)-1);INSERT INTO dbo.new_tacontract_directaccount_rrBase( new_tacontract_directaccount_rrId, new_tacontractid, new_directaccountid)VALUES(newid(),@objectId,@dirId)set @dirsdisplay = isnull(@dirsdisplay,'') + case when isnull(@dirsdisplay,'') = '' then '' else ';' end +  replace(@tmpstr,convert(varchar(50),@dirId ) + '[:]', '');select @dirs = replace(@dirs, @tmpstr + '[;]','')set @breakindex = @breakindex + 1;if(@breakindex > 10000) break;endupdate d setNew_tacontract_actdirectaccount_display = @dirsdisplayfrom New_tacontractExtensionBase dwhere d.New_tacontractId = @objectIdset @idx = @idx + 1;endend

----------------------------------------------------------------------------------------------------------------------------------------------
精准广告执行单:

 建立两个字段([实际投放客户]一个带display的,一个不带<nvarchar>),
 建立一个多对多关系(直客客户)

 表单增加字段(实际投放客户[不带display])

 

 

----------------------------------------------------------------------------------------------------------------------------------------------

 项目中精准广告执行单的Onload.js中增加JS控制Lookup的JS代码块(或者在表单属性的Onload事件中添加也一样)

    //实际投放人员 2015-10-27 16:40:38 彭振    document.getElementById('new_taorder_actdirectaccount').fetchxml = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\"><entity name=\"new_directaccount\"><attribute name=\"new_name\"/><order attribute=\"new_name\" descending=\"false\"/><filter type=\"and\"><condition attribute=\"new_name\" operator=\"like\" value=\"%%\"/><condition attribute=\"new_directaccount_businessline\" operator=\"like\" value=\"%AU%\"/><condition attribute=\"statecode\" operator=\"eq\" value=\"0\"/></filter></entity></fetch>";    var mylookupbrand = new MyLookupControl("new_taorder_actdirectaccount", "直客客户", "new_name", "/CRM/readonly.aspx?objTypeCode=10198&id=");

----------------------------------------------------------------------------------------------------------------------------------------------

 数据库中的触发器添加相对应的截取转换插入代码块

--实际使用客户字段格式化 2015-10-27 16:04:17 彭振 IF(update(new_taorder_actdirectaccount))begindeclare @tmptb table(idx int identity primary key, objectId uniqueidentifier,dirs nvarchar(max))declare @objectId uniqueidentifier,@breakindex int,@tmpstr nvarchar(max);insert into @tmptbselect New_taorderId,New_taorder_actdirectaccount from INSERTED ideclare @idx int;set @idx = 1;while(exists(select idx from @tmptb t where t.idx = @idx))begindeclare @dirs nvarchar(max), @dirsdisplay nvarchar(max);select @objectId = objectId,@dirs = dirs + '[;]' from @tmptb t where t.idx = @idx;set @dirsdisplay = null;delete ds from new_taorder_directaccount_rrBase ds where ds.new_taorderid = @objectIdset @breakindex = 0;while(len(@dirs) > 0)begindeclare @dirId uniqueidentifier;set @tmpstr = left(@dirs, charindex('[;]',@dirs)-1)set @dirId = left(@tmpstr, charindex('[:]',@tmpstr)-1);INSERT INTO dbo.new_taorder_directaccount_rrBase( new_taorder_directaccount_rrId, new_taorderid, new_directaccountid)VALUES(newid(),@objectId,@dirId)set @dirsdisplay = isnull(@dirsdisplay,'') + case when isnull(@dirsdisplay,'') = '' then '' else ';' end +  replace(@tmpstr,convert(varchar(50),@dirId ) + '[:]', '');select @dirs = replace(@dirs, @tmpstr + '[;]','')set @breakindex = @breakindex + 1;if(@breakindex > 10000) break;endupdate d setNew_taorder_actdirectaccount_display = @dirsdisplayfrom New_taorderExtensionBase dwhere d.New_taorderId = @objectIdset @idx = @idx + 1;endend

----------------------------------------------------------------------------------------------------------------------------------------------

 在精准广告合同的自定义实体中的一对多关系中,找到【精准广告执行单】关系
 建立【实际投放客户】映射关系

 

 

 

 

 

 

0 0