[英]Programmatically creating an article in Dynamics CRM 2011
我有一個能夠在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);
一些東西...
article["subject"] = articleSubject;
subject
不是kbarticle
實體的有效屬性。 subjectid
只是將需要一個Lookup
到一個有效的主題記錄。 我不知道你的片段是否存在。
根據SDK ,您還需要指定KB模板:
創建知識庫文章時,必須將其與知識庫模板和主題相關聯...
[剪斷]
要將文章與模板相關聯,請使用KbArticle。 KbArticleTemplateId屬性。 要通過指定主題將文章放在特定類別中,請使用KbArticle.SubjectId屬性。
此外,可能不是您的錯誤的來源,但您的代碼嘗試兩次創建文章。 你的第一行代碼是多余的:
service.Create(article);
Guid articleGUID = service.Create(article);
除此之外,我們確實需要知道您的代碼引發的錯誤(盡管我懷疑它將是我的第一點)。
感謝您的回答,他們都幫助我找到了正確的解決方案。 主要問題是我需要為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);
應該是這樣的
KbArticle a = new KbArticle();
a.Title = articleTitle;
a.SubjectId = new Xrm.Sdk.EntityReference(Subject.EntityLogicalName, subjectGuid);
service.Create(a);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.