如何根据crm 2011中的视图过滤条件更新实体

时间:2013-03-27 12:17:46

标签: xml views dynamics-crm-2011 crm fetch

我正在尝试创建一个按钮,该按钮将根据视图中的过滤条件获取所有记录,直到现在我可以创建按钮并运行一个页面来执行实体中所有记录的更新,但现在我需要要在视图中应用过滤条件,有什么想法吗?有可能吗?

2 个答案:

答案 0 :(得分:0)

您需要在Javascript中执行此操作吗?您可以在插件中执行保存的视图(名为SavedQuery),试试这个:

using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
{
    var viewFetchXml = (from q in svcContext.CreateQuery<SavedQuery>()
                        where q.Name == "Saved Query Name"
                        select q.FetchXml).FirstOrDefault();
    if (viewFetchXml != null)
    {
        FetchExpression query = new FetchExpression(viewFetchXml);
        EntityCollection results = _serviceProxy.RetrieveMultiple(query);    
    }
}

答案 1 :(得分:0)

@Pedro,我不知道这是否接近?我认为这必须通过自定义工作流活动或插件来完成!

protected static EntityCollection GetInfo(string EntityName)
        {
            OrganizationService _orgService;
            String connectionString = CrmClasses.Operations.Configuration.GetServiceConfiguration();

            CrmConnection connection = CrmConnection.Parse(connectionString);
            using (_orgService = new OrganizationService(connection))
            {
                QueryExpression request = new QueryExpression
                {
                    EntityName = EntityName,
                    ColumnSet = new ColumnSet { AllColumns = true },
                    Criteria =
                    {
                        Filters =
                                    {
     // -------------- insert here the filters criteria view?????????? --------
                      }
                    }                           
                };
                EntityCollection retrieved = _orgService.RetrieveMultiple(request);
                return retrieved;
            }
        }
        #endregion