转载CRM相关摘录

来源:互联网 发布:税友软件集团有限公司 编辑:程序博客网 时间:2024/06/06 19:54

以下内容转自:

http://liuzujun0608.blog.163.com/
一、CRM 屏蔽鼠标右键:

1/_static/_common/scripts/Global

代码块:

function document.oncontextmenu()

{

var s = event.srcElement.tagName;

// Only allow context menus if:

// the element is not disabled AND

// the element is either a TextArea OR a TextBox OR a user selection in some TextBox/TextArea

event.returnValue =

(!event.srcElement.disabled &&

(document.selection.createRange().text.length > 0 ||

s == "TEXTAREA" ||

s == "INPUT" && event.srcElement.type == "text"));

}

注:注释掉就OK

 

二、使lookup 类型实现多选的查找视图

var table=document.getElementById("zz_zywxid");

table.lookupstyle="multi";

 

三、crm插件实例代码及解释

     插件示例代码: 

 

public void Execute(IPluginExecutionContext context)

{

   DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];

   if (entity.Name == EntityName.account.ToString())

        {

            Guid id = (Guid)context.OutputParameters.Properties["Id"];

            Key myKey = new Key(id);

            if (!entity.Properties.Contains("accountid"))

            {

                entity.Properties["accountid"] = myKey;

            }

            if (!entity.Properties.Contains("description"))

            {

                entity.Properties["description"] = "GUID = " + id.ToString();

                ICrmService service = context.CreateCrmService(true);

                service.Update(entity);

            }

        }

    }

 

  分析:

    context.InputParameters:触发事件的Request Message的参数,类型是PropertyBag。根据PropertyBag类的描述,它代表实体实例。也就是说这个实体实例的某个事件,如创建或者修改或者删除,触发了当前插件的执行。实体实例是由很多Property构成的,所以它的Properties属性保存了它的所有Property的集合。在这个集合中,有一个名称为"Target"的属性,通过集合的["Target"]操作取得"Target"属性的值。这个值的实际类型是DynamicEntity,而集合中返回的的是通用的Object类型,所以通过(DynamicEntity)强制转换。

    DynamicEntity:只有实体名称和一组属性的BusinessEntity。系统和自定义实体是有强类型属性的BusinessEntity。一个实体实例都应该有一个唯一的标识,类似于数据库中的记录主键。当一个实体还在插件阶段处理时,在CRM后台数据库中可能还不存在,有些信息还没有最后确定,所以称为动态的。

    entity.Name:这个动态实体的名称。

    EntityNameSDK中定义的一个Enum类型,包括了所有内建的实体名称。EntityName.account代表系统的帐户实体。EntityName.account.ToString()表示帐户实体的实体名称。整个条件语句标识判断动态实体是否是帐户实体。

    context.OutputParameters:与context.InputParameters类似。代表经过插件处理后的Response Message的参数,也是PropertyBag类型的对象。整行是返回名称为"Id"的属性的属性值。这个值的实际类型是System.Guid类型。

     Key myKey = new Key(id):通过id对象构造Key对象。对于任何一个实体实例来说,都有一个Key对象作为它的唯一标识。

     if (!entity.Properties.Contains("accountid")):如果这个动态实体是accoun类型的实体,那么它的属性集合中一定是包含名称为"accountid"的属性。通过集合的Contains方法来做判断。

     entity.Properties["accountid"] = myKey:给这个动态帐户实体赋一个id值。根据account实体的定义,这个id值必须存储在"accountid"属性中。

     if (!entity.Properties.Contains("description")):如果动态实体中不包含"description"属性。

     entity.Properties["description"] = "GUID = " + id.ToString():给动态实体实例创造一个"description"属性,并且给它赋值。

     ICrmService service = context.CreateCrmService(true):通过context获取ICrmService。后者提供web service的形式让开发者可以对实体实例进行操作的功能。

     service.Update(entity):把动态实体更新保存到后台。

 

四、取出MSCRM父窗口的欄位的值
如果從父表單開啟,則可以取到父表單的值

if (
    (window.opener != null) &&
    (window.opener.parent != null) &&
    (window.opener.parent.document != null) &&
    (window.opener.parent.document.crmForm != null)) {
    //This is the parent form
    var parentForm = window.opener.parent.document.crmForm;    
    var xx= parentForm.all.{FieldName}.DataValue ;    
}

 

五、定时刷新页面
There is aspx page for Incident as CS/home_cases.aspx. Which basically
renders Incident View. I added my script in this page
var refreshBtn = document.getElementById("refreshButton");
if(refreshBtn != null)
{
setInterval("crmGrid.Refresh()",5000)
}
And it worked !!!!


六、crm 日常管理的一些小技巧

//隐藏左侧菜单

if(window.document.getElementById( 'navAsyncOperations')!=null)

{
      window.document.getElementById( 'navAsyncOperations').style.display = 'none';
 }; 

//表单的头名称
document.title,可改,可做变化,不啰嗦了

//整个表单只读
document.body.disabled = true;

这个灰掉了,有点难看,但是网上给出的灰掉这个表单的方法太麻烦,作用一样,简单何乐而不为
唯一缺陷,iframe里的关联视图是怎么也灰不掉的,请高手指点
//隐藏isvbuttion
var liBtns = window.document.getElementsByTagName("LI");

  for(var i = 0; i < liBtns.length; i++)
 {
     if( liBtns.id == "_MBcrmFormSubmitCrmForm59truetruefalse"||liBtns.action == "crmForm.Print();"|| liBtns.id =="action")
                  liBtns.style.display = "none";
  }

可用id,可用action,可用alt,估计样式也可以改,用ietoolbar可以抓到数据错误后定位,不刷新表单一定要:
crmForm.all.
字段名.SetFocus();
    event.returnValue = false;
    return false;
隐藏左侧菜单,去掉关联视图的button,等常见方法网上都有,不多说了
Changing the label of a field at runtime
crmForm.all.revenue_c.innerText = "Amount Euro";

 

原创粉丝点击