Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. CRM. SDK. messages;
Using Microsoft. xrm. SDK. query;
/// <Summary>
/// Knowledge Base Article
/// </Summary>
Public class kbarticlehelper
{
Public static readonly string entityname = "kbarticle ";
Public guid kbarticleid = guid. empty;
Public iorganizationservice service;
/// <Summary>
/// Create a Knowledge Base Article
/// </Summary>
Public void create ()
{
Entity en = new entity () {logicalname = entityname };
En ["title"] = "Knowledge Base Article test ";
Kbarticleid = service. Create (en );
}
/// <Summary>
/// Retrieve the top 10 Knowledge Base articles of a specified product
/// </Summary>
/// <Param name = "productid"> product ID </param>
Public void retrievebytopincidentproductkbarticle (guid productid)
{
Retrievebytopincidentproductkbarticlerequest request = new retrievebytopincidentproductkbarticlerequest ();
Request. productid = productid;
Retrievebytopincidentproductkbarticleresponse response =
(Retrievebytopincidentproductkbarticleresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}
/// <Summary>
/// Retrieve the first 10 articles in the knowledge base on the specified topic
/// </Summary>
/// <Param name = "subjectid"> topic id </param>
Public void retrievebytopincidentsubjectkbarticle (guid subjectid)
{
Retrievebytopincidentsubjectkbarticlerequest request = new retrievebytopincidentsubjectkbarticlerequest ();
Request. subjectid = subjectid;
Retrievebytopincidentsubjectkbarticleresponse response =
(Retrievebytopincidentsubjectkbarticleresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}
/// <Summary>
/// Search for all document indexes that contain the specified text in the body
/// </Summary>
/// <Param name = "query"> query condition </param>
/// <Param name = "text"> specify text </param>
/// <Param name = "subjectid"> topic id </param>
Public void searchbybodykbarticle (querybase query, string text, guid subjectid)
{
Searchbybodykbarticlerequest request = new searchbybodykbarticlerequest ();
Request. queryexpression = query;
Request. useinflection = true;
Request. searchtext = text;
Request. subjectid = subjectid;
Searchbybodykbarticleresponse response = (searchbybodykbarticleresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}
/// <Summary>
/// Search for all document indexes containing the specified keyword
/// </Summary>
/// <Param name = "query"> query condition </param>
/// <Param name = "text"> specify text </param>
/// <Param name = "subjectid"> topic id </param>
Public void searchbykeywordskbarticle (querybase query, string text, guid subjectid)
{
Searchbykeywordskbarticlerequest request = new searchbykeywordskbarticlerequest ();
Request. queryexpression = query;
Request. useinflection = true;
Request. searchtext = text;
Request. subjectid = subjectid;
Searchbykeywordskbarticleresponse response = (searchbykeywordskbarticleresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}
/// <Summary>
/// Search for all document indexes whose titles contain the specified text
/// </Summary>
/// <Param name = "query"> query condition </param>
/// <Param name = "text"> specify text </param>
/// <Param name = "subjectid"> topic id </param>
Public void searchbytitlekbarticle (querybase query, string text, guid subjectid)
{
Searchbytitlekbarticlerequest request = new searchbytitlekbarticlerequest ();
Request. queryexpression = query;
Request. useinflection = true;
Request. searchtext = text;
Request. subjectid = subjectid;
Searchbytitlekbarticleresponse response = (searchbytitlekbarticleresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}
/// <Summary>
/// Delete a Knowledge Base Article
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, kbarticleid );
}
}
CRM Operation Knowledge Base Article entity