none
为实体自动编号后如何在自动编号上加上当前系统日期 RRS feed

  • 问题

  • 目前已经实现了自动编号1、2、3。。。,但是如何在自动编号上加上当前系统日期,实现编号“YYYYMMDD+三位流水号”这种格式的编号呢?另外还有个就是“客商编码+3位流水号”,客商编码是其中一个实体中的编号,如何根据关联的客商读取其客商编号然后再实现“客商编码+3位流水号”格式的自动编号呢?
    2010年6月17日 9:49

答案

  • 写插件一般都是用sdk, 写Isv的Web 页面用Web Service. 不过这都不是绝对的, 我也见过用Web Service  写Plugin的.

    先下载 sdk

    然后进sdk\server\fullsample\pluginpostinvoice\目录

    2010年7月11日 13:26

全部回复

  • 在PrePlugin里做日期的比对.然后再加上客商编码就可以组成整个的自动编码了
    2010年6月19日 6:26
  • 目前问题是不知道如何加上客商编码?就是需要自动编号的实体表单中本来就有个客商名称,我们现在需要做的是把客商名称对应的客商编码找出来,然后加到自动生成的编号当中
    2010年6月21日 3:18
  • Retrieve(客商)得到客商编码,然后再用客商编码+自动编码,这样做不到吗?应该比较容易吧
    2010年6月21日 5:42
  • 小宁,您好!

    Retrieve(客商)得到客商编码,这部分有没有一个例子可供参考的?目前我在plug-in中就是不清楚应该如何进行Retrieve(客商)得到客商编码。谢谢!

    2010年6月28日 2:58
  • // 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);
    2010年6月28日 5:00
  • 小宁,您好!

    目前我已经知道怎么获取客商实体,但是如果要根据客商名称找到对应的客商实体实例的Guid,不知道如何才可以取到呢?谢谢!

    2010年6月30日 3:21
  • 用QueryExpression去查询
    2010年6月30日 3:37
  • 小宁,您好!

    可以给一下QueryExpression去查询的例子吗?谢谢!

    2010年6月30日 4:21
  • // 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
    2010年6月30日 7:35
    版主
  • 版主,您好!

    使用QueryExpression方法的时候

    condition.AttributeName = "address1_city";
    condition.Operator = ConditionOperator.Like;
    condition.Values = new string [] {"Sammamish"};

    condition.AttributeName是Lookup类型的时候怎么进行查询呢?还可以直接定义成like条件吗?谢谢!

    2010年7月1日 2:36
  • 另外还想问下,如果是lookup类型的话,是不是这样写的?这样写对吗?谢谢!

                       condition.AttributeName = "new_customername";
                       condition.Operator = ConditionOperator.Equal;
                       condition.Values = new Microsoft.Crm.Sdk.Lookup[] { visitcustomercode };

     

    2010年7月1日 2:58
  •                     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
    2010年7月1日 3:14
    版主
  • { ((Key)entity.Properties["quoteid"]).Value };这里 是一个guid


    Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com
    2010年7月1日 3:15
    版主
  • 直接用QueryExpression可不可以根据客商名称查询出客商编码呢?
    2010年7月1日 3:41
  • 客商编码不是主键来的
    2010年7月1日 3:42
  • 版主上面的QueryExpression例子的意思应该是在account这个实体里面查询属性值为address1_city  like  “Sammamish”的实例吧?

    目前我主要是想在客商信息(自定义实体)通过客商名称查询出客商编码,而客商名称是lookup类型的,客商编码只是一个属性,不是主键。那是不是应该这样写呢?

                       condition.AttributeName = "new_customername";
                       condition.Operator = ConditionOperator.Equal;
                       condition.Values = new Microsoft.Crm.Sdk.Lookup[] { visitcustomercode };

    然后在query中指明实体为客商信息就可以了?谢谢!

    2010年7月1日 3:51
  • 那得用连接查询了

    [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
    2010年7月1日 8:26
    版主
  • // 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

    咋整呀?!

    2010年7月8日 16:55
  • sdk,和Web Service的用法是不一样的.sdk要用filter.Conditions.Add
    2010年7月9日 2:06
  • sdk,和Web Service的用法是不一样的.sdk要用filter.Conditions.Add


    小宁,你这样说也可以理解,可是crm4.0的sdk里说,一边说写插件要用sdk,一边又把插件的Sample Code 搞成Web Service ,实在搞不懂啥意思啊。

    哪里有sdk的实例Sample Code可以看一看呀?

    2010年7月9日 9:33
  • 写插件一般都是用sdk, 写Isv的Web 页面用Web Service. 不过这都不是绝对的, 我也见过用Web Service  写Plugin的.

    先下载 sdk

    然后进sdk\server\fullsample\pluginpostinvoice\目录

    2010年7月11日 13:26
  • 写插件一般都是用sdk, 写Isv的Web 页面用Web Service. 不过这都不是绝对的, 我也见过用Web Service  写Plugin的.

    先下载 sdk

    然后进sdk\server\fullsample\pluginpostinvoice\目录

    多谢小宁仗义回答.
    • 已建议为答案 laterlu 2010年7月24日 13:17
    2010年7月11日 15:41
  • 怎么不说结案啊?
    2010年7月16日 1:43