编程知识 cdmana.com

Dynamics CRM JavaScript 操作大全

Dynamics CRM JavaScript 操作大全

一:js给字段赋值
1、单行文本
Xrm.Page.getAttribute(‘Singlelinetext’).setValue(“单行文本数据”);
2、整数
Xrm.Page.getAttribute(‘integer’).setValue(190 );
3、选项集
Xrm.Page.getAttribute(‘OptionSet’).setValue(100000001);
4、两个选项
Xrm.Page.getAttribute(‘OptionSet’).setValue(true);
5、浮点数
Xrm.Page.getAttribute('new_Float ').setValue(10.2);
6、十进制数
Xrm.Page.getAttribute('new_Float ').setValue(104.1);
7、货币
Xrm.Page.getAttribute('new_Float ').setValue(20000.1);
8、多行文本
Xrm.Page.getAttribute('new_Float ').setValue(“多行文本字段的值多行文本字段的值多行文本字段的值多行文本字段的值----多行文本字段的值”);
9、日期和时间
Xrm.Page.getAttribute('new_Float ').setValue(new date());
10、查找
attr(‘实体名称’).disable().setLookup(‘实体名称’, 查找实体的值, 查找实体的name)



















二:c#给各类型字段赋值
1、单行文本
RecordEntity[“new_lead”]=“单行文本的值”;
2、整数
RecordEntity[“new_lead”]=123;
3、选项集
RecordEntity[“实体名”]= new OptionSetValue(100000003);
4、两个选项
RecordEntity[“new_isornoappoint”] = true;
5、浮点数
RecordEntity[“float”] =10.1;
6、十进制数
RecordEntity[“decimalism”] =10.20;
7、货币
RecordEntity[“new_ftmoney”] = new Money(90.0);
8、多行文本
RecordEntity[“new_ftmoney”] =“多行文本的值”;
9、日期和时间
RecordEntity[“date”] =datetime.now;
10、查找
RecordEntity[“实体名称”]=new EntityReference(“关联实体的名称”, 关联实体的guid);;



















三:Linq查询
单表
场景1、OrganizationServiceContext orgServiceContext=new OrganizationService(service);

var result=from a in orgServiceContext.CreateQuery(“Account”) select a;
遍历集合
foreach(var item in result)
{
xx=item[“attributename”];
}
场景2、
var sql=from a in orgServiceContext.CreateQuery(“Account”)
Where a[“accounted”].Equals(xxxx)
Select new Account
{
AccountName=a[“accountName”],
Account_Address=a[“address”]
}
遍历集合
Foreach(var item in sql)
{
xxx=item[“AccountName”];//这里取值时用select的别名
}
多表
var sql=from a in orgServiceContext.CreateQuery(“systemuser”)
join b in orgServiceContext.CreateQuery(“systemuserroles”)
on a.systemuserid equals b.systemuserid
join c in orgServiceContext.CreateQuery(“role”)
on b.roleid equals c.roles
where a[“name”].equals(“xxxx”)
Orderby a.name ascending
Select new
{
Name=a.name,
Role_Id=c.roleid
};
场景3 :对大型查询结果集进行分页
int pageSize=5;
var accountByPage=from a in orgServiceContext.CreateQuery(“Account”)
select new Account
{
Name=a.name
};
Foreach






































四、fetchXml
单表:
string fetch=@"<fetch version=’'1.0 outpu-format=‘xml-platform’ mapping=‘logical’ distinct=‘true’>

";
EntityCollection results=service.RetrieveMultiple(new FetchExpression(fetch));




多表:
string fetch=@"






<link_entity name=‘systemuserroles’ from=‘systemuserid’ to=‘systemuserid’ visable=‘false’ intersect=‘true’>
<link_entity name=‘role’ from =‘roleid’ to=‘roleid’ alias=‘aa’>







";
EntityCollection results=service.RetrieveMultiple(new FetchExpression(fetch));

















五、QueryBase
单表:
QueryExpression query=new QueryExpression{
EntityName=“account”,
ColumnSet=new ColumnSet(true);
}




多表:
例:select a.ename,b.bname from emp a join dept b on a.deptno=b.deptno join customer c on b.customerid=c.customerid

QueryExpression query = new QueryExpression();
query.EntityName = “emp”;
query.ColumnSet = new ColumnSet();
query.ColumnSet.Columns.Add(“ename”);


        LinkEntity linkEntity = new LinkEntity("emp", "dept", "deptno", "deptno", JoinOperator.Inner);

        query.LinkEntities.Add(linkEntity); 
        query.LinkEntities[0].Columns.AddColumns("bname");
        query.LinkEntities[0].EntityAlias = "b";

LinkEntity linkEntity2 = new LinkEntity(“dept”, “customer”, “customerid”, “customerid”, JoinOperator.Inner);

        query.LinkEntities.Add(linkEntity2);
        query.LinkEntities[1].Columns.AddColumns("customername");
        query.LinkEntities[1].EntityAlias = "c";

        EntityCollection results = service.RetrieveMultiple(query);

        //遍历结果集
foreach(Entity entity in results.Entities){
             string name=entity["ename"];  //from表直接获取
 string bname=entity["b.bname"]; //这里要取dept的值需要通过别名取得
 string customername=entity["c.customername"]; //这里要取customer的值需要通过别名取得
}

版权声明
本文为[osc_zg8wy3xa]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4373561/blog/4836449

Scroll to Top