With the introduction of the new knowledge articles entity data model (KnowledgeArticle) in Dynamics CRM Online 2016 Update 1 and Microsoft Dynamics CRM 2016 SP1 (for on premise) (Release documentation 8.1 – January 2017) , the existing entities for knowledge management: KbArticle, KbArticleComment and KbArticleTemplate were deprecated.
You should now use the newer KnowledgeArticle in your code (See Important changes coming in future releases of Microsoft Dynamics 365), which also support versioning and translation support.
In version 8.1, these knowledge articles became visible in the interactive service hub which was revamped into the Customer Service Hub in version 9.0 (Dynamics 365 July 2017 update). The Customer Service Hub also contains a number Knowledge Base dashboard - one with "your knowledge base articles" and one specifically for a knowledge manager (see screenshot below).
If you want to learn more about how to work with knowledge base articles, you should really take a look at Reduce call handling times with knowledge articles in the Customer Service Hub . Knowledge base articles are also directly shown in a tab on a case form (see screenshot below).
- QueryExpression: used to set additional query criteria and for which you also need to set the PagingInfo otherwise no results are returned
- RemoveDuplicates: remove duplicate versions of the same Knowledge Article
- SearchText: the text to search for in Knowledge Articles
- StateCode: required parameter which accepts an integer for the different statuses of a knowledge article such as Published, Draft, Approved, etc…
- UseInflection: searches for all different tenses of a verb or both the singular and plural forms of a noun. Underlying SQL full-text search is used (For more details see Searching for the inflectional form of a specific word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void QueryKB(string searchtext) | |
{ | |
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; | |
var client = new CrmServiceClient(username, CrmServiceClient.MakeSecureString(password), "EMEA", | |
orgname, useUniqueInstance: false, useSsl: true, isOffice365: true); | |
if (client.IsReady) | |
{ | |
var orgsvc = (IOrganizationService)client.OrganizationServiceProxy; | |
//knowledgearticle - new entity to be used vs kbarticle - deprecated functionality | |
QueryExpression qry = new QueryExpression("knowledgearticle"); | |
qry.ColumnSet = new ColumnSet(true); | |
//Gotcha - you need to provide PagingInfo otherwise you will get no results | |
qry.PageInfo = new PagingInfo(); | |
qry.PageInfo.PageNumber = 1; | |
qry.PageInfo.Count = 10; | |
//Statecode = 3 is Published | |
FullTextSearchKnowledgeArticleRequest searchKBRequest = new FullTextSearchKnowledgeArticleRequest() | |
{ | |
UseInflection = true, | |
SearchText = searchtext, | |
RemoveDuplicates = false, | |
QueryExpression = qry, | |
StateCode = 3 | |
}; | |
var searchKBResponse = (FullTextSearchKnowledgeArticleResponse)orgsvc.Execute(searchKBRequest); | |
EntityCollection retrievedArticles = searchKBResponse.EntityCollection; | |
//Use retrievedArticles.MoreRecords if you want to retrieve next pages with results | |
if (retrievedArticles.Entities.Count > 0) | |
{ | |
foreach (Entity item in retrievedArticles.Entities) | |
{ | |
Console.WriteLine("{0} - {1} (Number of views:{2} - Language: {3})", | |
item.Attributes["articlepublicnumber"].ToString(), item.Attributes["title"].ToString(), | |
item.Attributes["knowledgearticleviews"].ToString(), | |
((EntityReference)item.Attributes["languagelocaleid"]).Name); | |
} | |
} | |
Console.WriteLine("No knowledgebase articles found ...."); | |
} | |
else | |
{ | |
Console.WriteLine("Unable to connect to {0} - {1}", orgname, client.LastCrmError); | |
} | |
} |
References:
No comments:
Post a Comment