Reputation: 21
I have a plugin that is able to update a case in CRM, but I now want it to create a new knowledge base article, as I don't believe it is possible to automate this using a workflow. The plugin is triggered by a workflow that is executed when a case is resolved.
Here is what I have so far but it does not work:
Entity article = new Entity("kbarticle");
article["title"] = articleTitle;
article["subject"] = articleSubject;
service.Create(article);
Guid articleGUID = service.Create(article);
ColumnSet attributes = new ColumnSet(new string[] { "description" });
article = service.Retrieve(article.LogicalName, articleGUID, attributes);
article["description"] = articleDescription;
service.Update(article);
Upvotes: 1
Views: 2562
Reputation: 21
thanks for the answers, they all helped to send me in the right direction towards a solution. The main issue was that I needed to use entity references for the subjectid and template:
Entity kbarticle = new Entity("kbarticle");
kbarticle["title"] = title;
kbarticle["subjectid"] = new EntityReference(subject_LogicalName, subject_Guid);
kbarticle["kbarticletemplateid"] = new EntityReference(template_LogicalName, template_Guid);
service.Create(kbarticle);
Upvotes: 1
Reputation: 3878
A few things...
article["subject"] = articleSubject;
subject
is not a valid attribute on the kbarticle
entity. subjectid
is but will need to be a Lookup
to a valid subject record. I can't tell from your snippet if it is or not.
According to the SDK, you also need to specify a KB template:
When you create a knowledge base article, you have to associate it with a knowledge base template and a subject...
[snip]
To associate an article with a template, use the KbArticle. KbArticleTemplateId attribute. To place an article in a specific category by specifying a subject, use the KbArticle.SubjectId attribute.
Also, probably not the source of your error, but your code tries to create the article twice. Your first line of code here is redundant:
service.Create(article);
Guid articleGUID = service.Create(article);
Beyond that, we really do need to know the error that is raised by your code (though I suspect it will be my first point).
Upvotes: 2
Reputation: 17562
Have you seen this MSDN article, its not a code example but it describes the steps to create an article.
Edit:
You need to provide us with more debugging information. Either;
You would probably find it easier to develop the article creation code against unit tests in Visual Studio, then you can just hook it up to a workflow activity later.
Upvotes: 0
Reputation: 2258
It should look like
KbArticle a = new KbArticle();
a.Title = articleTitle;
a.SubjectId = new Xrm.Sdk.EntityReference(Subject.EntityLogicalName, subjectGuid);
service.Create(a);
Upvotes: 0