当前位置: 代码迷 >> 综合 >> Dynamics 365 在Case实体上,替换View中的某个显示字段
  详细解决方案

Dynamics 365 在Case实体上,替换View中的某个显示字段

热度:93   发布时间:2024-01-16 08:56:10.0

在Case实体上,替换View中的某个显示字段

 

        [TestMethod]

        public void testsQureySavedQuery()

        {

string _strConn = "Url=https://qq-wip-dev1.crm5.dynamics.com; Username=h***@qq.com; authtype=Office365; Password=**";      

            string viewEntityName = "";

            viewEntityName = "incident";

            using (CrmServiceClient _serviceProxy = new CrmServiceClient(_strConn))

            {

                QueryExpression mySavedQuery = new QueryExpression

                {

                    ColumnSet = new ColumnSet("savedqueryid", "name", "querytype", "isdefault", "returnedtypecode", "isquickfindquery", "iscustomizable", "fetchxml", "layoutxml", "description"),

                    EntityName = "savedquery",

                    Criteria = new FilterExpression

                    {

                        Conditions =

                                {

                                    new ConditionExpression{AttributeName = "querytype",Operator = ConditionOperator.Equal,Values = {0}},

                                    new ConditionExpression{AttributeName = "returnedtypecode",Operator = ConditionOperator.Equal,Values = { viewEntityName }}

                                }

                    }

                };

                RetrieveMultipleRequest retrieveSavedQueriesRequest = new RetrieveMultipleRequest { Query = mySavedQuery };

                RetrieveMultipleResponse retrieveSavedQueriesResponse = (RetrieveMultipleResponse)_serviceProxy.Execute(retrieveSavedQueriesRequest);

                DataCollection<Entity> savedQueries = retrieveSavedQueriesResponse.EntityCollection.Entities;

 

                //Display the Retrieved views

                string viewName = "Level 3 Japan kevin";

                viewName = "aaaaaaa";

                string strname = "";

                string strdesc = "";

                foreach (Entity ent in savedQueries)

                {

                    strname = ent.GetAttributeValue<string>("name");

                    strdesc = ent.GetAttributeValue<string>("description");

                    if (viewName == strname)

                        if (strdesc != null && strdesc.Contains("All of cases belong to") && ent.GetAttributeValue<BooleanManagedProperty>("iscustomizable").CanBeChanged)

                        {

                            string outstr = string.Format("name={0},des={1}", strname, strdesc.Replace("\n", ""));

                            Console.WriteLine(outstr);                            string fxml = ent.GetAttributeValue<string>("fetchxml");

                            string lxml = ent.GetAttributeValue<string>("layoutxml");

                            Console.WriteLine(ent.GetAttributeValue<string>("fetchxml"));

                            Console.WriteLine(ent.GetAttributeValue<string>("layoutxml"));

                            Entity ventity = new Entity("savedquery");

                            ventity.Id = ent.Id;

                            ventity["fetchxml"] = fxml.Replace("customerid", "casenumber").Replace("\"", "'");

                            ventity["layoutxml"] = lxml.Replace("customerid", "casenumber").Replace("\"", "'");

                            //_serviceProxy.Update(ventity);

                            Console.WriteLine(fxml.Replace("customerid", "casenumber").Replace("\"", "'"));

                            Console.WriteLine(lxml.Replace("customerid", "casenumber").Replace("\"", "'"));

                        }

                }

            }

        }

 

ref:

https://docs.microsoft.com/zh-cn/previous-versions/dynamicscrm-2016/developers-guide/gg328457(v=crm.8)

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/savedquery?view=dynamics-ce-odata-9

  相关解决方案