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 );
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 .