简体   繁体   中英

Dynamics 365 SearchByTitleKbArticleRequest returns no records

I am trying to retrieve a kbarticle from Dynamics 365 online instance. I use a very simple query provided by SDK sample but it never returns any kbarticle.

Below is the code:

 SearchByTitleKbArticleRequest searchByTitleRequest =
                    new SearchByTitleKbArticleRequest()
                    {
                        SubjectId = subjectId, // I have retrieved subjectid earlier. 
                        UseInflection = false,
                        SearchText = "My Article",
                        QueryExpression = new QueryExpression()
                        {
                            ColumnSet = new ColumnSet(true),
                            EntityName = "kbarticle" // I've tried knowledgearticle as well.
                        }
                    };

var searchByTitleResponse = (SearchByTitleKbArticleResponse)
                    serviceProxy.Execute(searchByTitleRequest);

        // check success
        var retrievedArticles = searchByTitleResponse.EntityCollection.Entities;                      
        Console . WriteLine ( "  Results of search (titles found):" + retrievedArticles.Count ); // It is always 0
        foreach ( var article in retrievedArticles )
            Console . WriteLine ( article .Id );
  1. In the new version of SDK, kbarticle is renamed to knowledgearticle. I have tried using knowledgearticle with no luck.
  2. The connection to the CRM Online instance is also correct and I am able to run other queries with RetrieveMultiple service.
  3. The article is published and I have also permissions to access the article.
  4. I am able to retrieve the same article using REST and also using RetrieveMultiple, so I don't see any issue in the article or my connection.

Can anyone point me to the right direction to make this message working?

This depends on which entity you are using, below I'm giving the example for KnowledgeArticle.

Accordingly to Search knowledge articles using full-text search , the Knowledge Article are full-text indexed and support SQL Server full-text search.

You can use the FullTextSearchKnowledgeArticleRequest to search the articles.

var queryExpression = new QueryExpression("knowledgearticle")
{
    ColumnSet = new ColumnSet(true),
    PageInfo = new PagingInfo()
    {
        PageNumber = 1,
        Count = 5,
    }
};

FullTextSearchKnowledgeArticleRequest searchByTitleRequest =
        new FullTextSearchKnowledgeArticleRequest()
        {
            UseInflection = true,
            SearchText = "Error",
            RemoveDuplicates = false,
            StateCode = 0,
            QueryExpression = queryExpression
        };


var fullTextSearchKnowledgeArticleResponse = (FullTextSearchKnowledgeArticleResponse)
                   orgService.Execute(searchByTitleRequest);

// check success
var retrievedArticles = fullTextSearchKnowledgeArticleResponse.EntityCollection.Entities;
Console.WriteLine("Results of search (titles found):" + retrievedArticles.Count);
foreach (var article in retrievedArticles)
    Console.WriteLine(article.Id);

Note, there seems to be some time needed for the data to be indexed on SQL, which might not return a newly created article using the FullTextSearchKnowledgeArticleRequest .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM