Dynamics CRM JavaScript Operation Encyclopedia

Dynamics CRM JavaScript Operation Encyclopedia

One: js assigns values ​​to the field
1. Single-line text
Xrm.Page.getAttribute('Singlelinetext').setValue("Singlelinetext data");
2. Integer
Xrm.Page.getAttribute('integer').setValue(190 );
3 , Option set
Xrm.Page.getAttribute('OptionSet').setValue(100000001);
4. Two options
Xrm.Page.getAttribute('OptionSet').setValue(true);
5. Floating point number
Xrm.Page.getAttribute( 'new_Float').setValue(10.2);
6, Decimal number
Xrm.Page.getAttribute('new_Float').setValue(104.1);
7, Currency
Xrm.Page.getAttribute('new_Float').setValue(20000.1);
8 , Multi-line text
Xrm.Page.getAttribute('new_Float').setValue("Multi-line text field value, multi-line text field value, multi-line text field value, multi-line text field value-multi-line text field的值”);
9. Date and time
Xrm.Page.getAttribute('new_Float').setValue(new date());
10. Find
attr('entity name').disable().setLookup('entity name', find the value of the entity, find the name of the entity)

Two: c# assign values ​​to various types of fields
1. Single-line text
RecordEntity["new_lead"]="single-line text value";
2. Integer
RecordEntity["new_lead"]=123;
3. Option set
RecordEntity["entity name"]= new OptionSetValue(100000003);
4. Two options
RecordEntity["new_isornoappoint"] = true;
5. Floating point number
RecordEntity["float"] =10.1;
6. Decimal number
RecordEntity["decimalism"] = 10.20;
7. Currency
RecordEntity ["New_ftmoney"] = new Money(90.0);
8. Multi-line text
RecordEntity["new_ftmoney"] = "Value of multi-line text";
9. Date and time
RecordEntity["date"] =datetime.now;
10. Find
RecordEntity["Entity Name"]=new EntityReference("Name of associated entity", guid of associated entity);;

Three: Linq query
single table
Scenario 1, OrganizationServiceContext orgServiceContext=new OrganizationService(service);

var result=from a in orgServiceContext.CreateQuery("Account") select a;
traverse the collection
foreach(var item in result)
{ xx=item["attributename"]; } Scenario 2, var sql=from a in orgServiceContext.CreateQuery( "Account") Where a["accounted"].Equals(xxxx) Select new Account { AccountName=a["accountName"], Account_Address=a["address"] } Traverse the collection Foreach(var item in sql) { xxx= item["AccountName"];//The alias of select is used when taking the value here } multi-table 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的值需要通过别名取得
}

Guess you like

Origin blog.csdn.net/loginnamess/article/details/111515674