积极答复者
为实体自动编号后如何在自动编号上加上当前系统日期

问题
答案
全部回复
-
Retrieve(客商)得到客商编码,然后再用客商编码+自动编码,这样做不到吗?应该比较容易吧
- 已标记为答案 Jim Wang (Microsoft)Microsoft employee, Moderator 2010年6月21日 8:13
- 取消答案标记 Batistuta CaiModerator 2010年7月1日 5:11
-
// Create the column set object that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
// Set the properties of the column set.
cols.Attributes = new string [] {"name"};
// Create the target object for the request.
TargetRetrieveAccount target = new TargetRetrieveAccount();
// Set the properties of the target object.
// EntityId is the GUID of the record being retrieved.
// SDK: target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
target.EntityId = created.id;
// Create the request object.
RetrieveRequest retrieve = new RetrieveRequest();
// Set the properties of the request object.
retrieve.Target = target;
retrieve.ColumnSet = cols;
// Execute the request.
RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve); -
// Create the column set that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
// Set the properties of the column set.
cols.Attributes = new string [] {"name", "accountid"};
// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();
// Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};
// Create the FilterExpression.
FilterExpression filter = new FilterExpression();
// Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};
// Create the QueryExpression object.
QueryExpression query = new QueryExpression();
// Set the properties of the QueryExpression object.
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
// Create the request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
// Set the properties of the request object.
retrieve.Query = query;
// Execute the request.
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "quoteid";
condition1.Operator = ConditionOperator.Equal;
condition1.Values = new object[] { ((Key)entity.Properties["quoteid"]).Value };
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
版主上面的QueryExpression例子的意思应该是在account这个实体里面查询属性值为address1_city like “Sammamish”的实例吧?
目前我主要是想在客商信息(自定义实体)通过客商名称查询出客商编码,而客商名称是lookup类型的,客商编码只是一个属性,不是主键。那是不是应该这样写呢?
condition.AttributeName = "new_customername";
condition.Operator = ConditionOperator.Equal;
condition.Values = new Microsoft.Crm.Sdk.Lookup[] { visitcustomercode };然后在query中指明实体为客商信息就可以了?谢谢!
-
那得用连接查询了
[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = ""http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create a column set holding the names of the columns to be retrieved.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {"name", "accountid"};
// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();
// Set the condition to be when the account owner's last name is not Cannon.
condition.AttributeName = "lastname";
condition.Operator = ConditionOperator.Equal;
condition.Values = new string [] {"Cannon"};
// Build the filter that is based on the condition.
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};
// Create a LinkEntity to link the owner's information to the account.
LinkEntity link = new LinkEntity();
// Set the LinkEntity properties.
link.LinkCriteria = filter;
// Set the linking entity to account.
link.LinkFromEntityName = EntityName.account.ToString();
// Set the linking attribute to owninguser.
link.LinkFromAttributeName = "owninguser";
// The attribute being linked to is systemuserid.
link.LinkToAttributeName = "systemuserid";
// The entity being linked to is systemuser.
link.LinkToEntityName = EntityName.systemuser.ToString();
// Create an instance of the query expression class.
QueryExpression query = new QueryExpression();
// Set the query properties.
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.LinkEntities = new LinkEntity[] {link};
// Create the request.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
// Set the request properties.
retrieve.Query = query;
// Execute the request.
RetrieveMultipleResponse retrieved2 = (RetrieveMultipleResponse) service.Execute(retrieve);
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
// Create the column set that indicates the fields to be retrieved.
ColumnSet cols = new ColumnSet();
// Set the properties of the column set.
cols.Attributes = new string [] {"name", "accountid"};
// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();
// Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};
// Create the FilterExpression.
FilterExpression filter = new FilterExpression();
// Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};
// Create the QueryExpression object.
QueryExpression query = new QueryExpression();
// Set the properties of the QueryExpression object.
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
// Create the request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
// Set the properties of the request object.
retrieve.Query = query;
// Execute the request.
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.co
我在插件中依葫芦画瓢,编译通不过呀 filter.Conditions = new ConditionExpression[] {condition};
提示两个错误
错误 1 无法对属性或索引器“Microsoft.Crm.Sdk.Query.FilterExpression.Conditions”赋值 -- 它是只读的 E:\myProjects\YCCRMPlugin\AutoNumber.cs 32 29 YCCRMPlugin
错误 2 无法将类型“Microsoft.Crm.Sdk.Query.ConditionExpression[]”隐式转换为“System.Collections.ArrayList” E:\myProjects\YCCRMPlugin\AutoNumber.cs 32 75 YCCRMPlugin咋整呀?!