1

我有一个能够更新 CRM 中的案例的插件,但我现在希望它创建一个新的知识库文章,因为我不相信使用工作流可以自动执行此操作。该插件由解决案例时执行的工作流触发。

这是我到目前为止所拥有的,但它不起作用:

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

4 回答 4

2

一些东西...

无效属性

article["subject"] = articleSubject;

subject不是kbarticle实体上的有效属性。subjectid ,但需要是Lookup一个有效的主题记录。我无法从您的片段中判断它是否存在。

缺少属性

根据SDK,您还需要指定一个 KB 模板:

创建知识库文章时,必须将其与知识库模板和主题相关联...

[剪辑]

要将文章与模板关联,请使用 KbArticle。KbArticleTemplateId 属性。要通过指定主题将文章放入特定类别,请使用 KbArticle.SubjectId 属性。

冗余代码

此外,可能不是您的错误的来源,但您的代码尝试创建文章两次。您的第一行代码是多余的:

service.Create(article);

Guid articleGUID = service.Create(article);

除此之外,我们确实需要知道您的代码引发的错误(尽管我怀疑这将是我的第一点)。

于 2012-08-23T15:53:46.757 回答
1

感谢您的回答,他们都帮助我朝着解决方案的正确方向前进。主要问题是我需要为 subjectid 和模板使用实体引用:

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);
于 2012-08-24T08:40:43.590 回答
0

您是否看过这篇MSDN文章,它不是代码示例,而是描述了创建文章的步骤。

编辑:

您需要向我们提供更多调试信息。任何一个;

您可能会发现在 Visual Studio 中针对单元测试开发文章创建代码更容易,然后您可以稍后将其连接到工作流活动。

于 2012-08-21T13:50:18.323 回答
0

它应该看起来像

        KbArticle a = new KbArticle();
        a.Title = articleTitle;
        a.SubjectId = new Xrm.Sdk.EntityReference(Subject.EntityLogicalName, subjectGuid);
        service.Create(a);
于 2012-08-22T10:24:21.647 回答