문제

I need to retrieve a custom contacts view. I'm new to MS Dynamics development but was able to connect to the server and retrieve some basic info and found some examples of building the query/view in code using fetch xml but not to retrieve a custom view. Thanks

도움이 되었습니까?

해결책

This method will, if your custom view has a unique name (within the CRM Org), get the View and execute its FetchXml returning an EntityCollection. It should get you started with the basics which you can build out based on your more specific requirements.

This is starter/learning code only - not intended for deployment without error handling.

    public EntityCollection RetrieveCustomView(string viewName, IOrganizationService service)
    {
        var query = new QueryExpression()
        {
            EntityName = "savedview",
            ColumnSet = new ColumnSet("fetchxml"),
            Criteria = new FilterExpression()
            {
                Conditions = { new ConditionExpression("name", ConditionOperator.Equal, viewName) }
            }
        };

        var result = service.RetrieveMultiple(query);

        if (result.Entities.Any())
        {
            var fetchXml = result.Entities[0].Attributes["fetchxml"].ToString();

            var fetchQuery = new FetchExpression(fetchXml);

            return service.RetrieveMultiple(fetchQuery);

        }

        return null;
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top