0

我正在使用 CRM 4 和 SDK 来抓取这样的案例:

public List<Case> GetCases()
    {
        List<Case> cases = new List<Case>();


            #region Retrieve Resolved Cases
        try
        {

            InitSession();

            RetrieveMultipleRequest req = new RetrieveMultipleRequest();
            req.ReturnDynamicEntities = true;

            //QueryExpression says what entity to retrieve from, what columns we want back and what criteria we use for selection
            QueryExpression qe = new QueryExpression();
            qe.EntityName = EntityName.incident.ToString();
            List<string> attributes = new string[] { 
            "incidentid","title" ,"description", "ticketnumber", "statuscode",
            "kez_allocatedhours",
            "customerid",
            "casetypecode"

            }.ToList();

            //columns to retireve 
            ColumnSet AvailabilityColumnSet = new ColumnSet();
            AvailabilityColumnSet.Attributes = attributes.ToArray();
            qe.ColumnSet = AvailabilityColumnSet;

            //filter
            FilterExpression fe = new FilterExpression();
            fe.FilterOperator = LogicalOperator.And;

            //condtion for filter
            ConditionExpression isResolved = new ConditionExpression();
            isResolved.AttributeName = "statuscode";
            isResolved.Operator = ConditionOperator.NotEqual;
            isResolved.Values = new string[] { "5" };

            fe.Conditions = new ConditionExpression[] { isResolved }; //Add the conditions to the filter
           qe.Criteria = fe; //Tell the query what our filters are
            req.Query = qe; //Tell the request the query we want to use

            //retrieve entities
            RetrieveMultipleResponse resp = svc.Execute(req) as RetrieveMultipleResponse;
            if (resp != null)
            {
                BusinessEntity[] rawResults = resp.BusinessEntityCollection.BusinessEntities;
                List<DynamicEntity> castedResults = rawResults.Select(r => r as DynamicEntity).ToList();

                foreach (DynamicEntity result in castedResults)
                {
                    string id = GetProperty(result, "incidentid");
                    string title = GetProperty(result, "title");
                    string description = GetProperty(result, "description");
                    string ticket = GetProperty(result, "ticketnumber");
                    string customer = GetProperty(result, "customerid");
                    int statuscode = -1;
                    string statusname = "";
                    double estHours = 0.0;
                    string casetype = "";
                    int casetypecode = -1;

                    Property prop = result.Properties.Where(p => p.Name == "statuscode").FirstOrDefault();
                    if (prop != null)
                    {
                        StatusProperty status = prop as StatusProperty;

                        if (status != null)
                        {
                            statuscode = status.Value.Value;
                            statusname = status.Value.name;
                        }
                    }

                    prop = result.Properties.Where(p => p.Name == "kez_allocatedhours").FirstOrDefault();

                    if (prop != null)
                    {
                        CrmFloatProperty fl = prop as CrmFloatProperty;

                        if (fl != null)
                        {
                            estHours = fl.Value.Value;
                        }
                    }

                    prop = result.Properties.Where(p => p.Name == "casetypecode").FirstOrDefault();

                    if (prop != null)
                    {
                        PicklistProperty fl = prop as PicklistProperty;

                        if (fl != null)
                        {
                            casetype = fl.Value.name;
                            casetypecode = fl.Value.Value;
                        }
                    }

                    Case c = new Case();
                    c.ID = id;
                    c.Title = title;
                    c.Description = description;
                    c.StatusCode = statuscode;
                    c.StatusName = statusname;
                    c.TicketNumber = ticket;
                    c.CustomerName = customer;
                    c.EstimatedHours = estHours;
                    c.Type = casetype;
                    c.TypeCode = casetypecode;

                    bool allowedThroughStat = true;
                    bool allowedThroughType = true;
                    var userStatuses = SettingsManager.Get("CRMUserStatusReasons").Split(';').ToList().Where(p => p.Length > 0).ToList();
                    var userTypes = SettingsManager.Get("CRMUserCaseTypes").Split(';').ToList().Where(p => p.Length > 0).ToList();

                    if(userStatuses.Count > 0 && !userStatuses.Contains(c.StatusCode.ToString()))
                    {
                        allowedThroughStat = false;
                    }

                    if (userTypes.Count > 0 && !userTypes.Contains(c.TypeCode.ToString()))
                    {
                        allowedThroughType = false;
                    }

                    if(allowedThroughStat && allowedThroughType)
                    cases.Add(c);
                }

            }

        }// end try
        catch (Exception)
        {
            return null;
            // The variable 'e' can access the exception's information.
            // return "Error Message: " + e.Message.ToString() + " | Stack Trace: " + e.StackTrace.ToString();
        }

        return cases;

            #endregion
    }

但是,现在我需要能够在给定其事件 ID 的情况下从 C# 更改案例的状态和标题。

我查看了 SDK 文档,但找不到这样的示例。

以前有人用过这个吗?

谢谢

简单地说,上面是读取事件的代码。我可以举一个写事件字段的例子吗,只有一个。例如:我如何更改事件的标题。

4

2 回答 2

1

您可以在 CrmService 上调用 Update 方法。这是SDK 文章

Case c = new Case();
c.ID = id;
c.Title = title;
svc.Update(c); 
于 2013-04-15T18:45:36.953 回答
0

要更改实体的状态,请使用 setstaterequest。如果您想对动态实体执行此操作,则此博客中有描述

于 2013-04-17T09:48:27.327 回答