Attaching a Knowledge Article to a Case

  • 1
  • Question
  • Updated 5 months ago
  • Doesn't Need an Answer
I tried this a few years ago in another life, but we ended up being able to skip the issue by using solutions. I can't avoid it this time, so I'm hoping someone can help me.


I'm trying to give users a button to attach knowledge articles to a case. I've been able to return the list of knowledge articles by loading a model for the specific article type (Support Procedure) and setting a condition of PublishStatus = 'Online'. This allows me to show the Support Procedures in a table without an issue.

However, in order to attach an article I need to be able to create a new record in CaseArticle where the Case ID and the Knowledge Article Version ID are set. 

This is where things get dicey. If I look at this guide for knowledge development (https://resources.docs.salesforce.com/sfdc/pdf/salesforce_knowledge_dev_guide.pdf) specifically on page 13, I see that it breaks down to basically

Case -> CaseArticle -> Knowledge Article (Support_Procedure_ka) -> Knowledge Article Version (Support Procedure_kav).

If I try to take the simple route and create a new CaseArticle, I can't see KnowledgeArticle VersionIds, however if I set the KnowledgeArticleVersionId to a template field and put it as this: {{{KnowledgeArticleVersionId}}} it shows up just fine for existing CaseArticles. Here's an example showing both the Knowledge Article and Knowledge Article Version.



Once I try to create a new one and search for a Knowledge Article (not version, which doesn't allow me to search) however it returns no results and gives me some fun errors:




So to my question: Does anyone have any experience with Knowledge Articles and attaching them? I feel like I'm either running into a bug at this point, but I'm not sure how to work around it.



Here's my XML if needed (you would need to change the sobject to your own article type):




<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="SupportProcedure" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Support_Procedure__kav">
            <fields>
                <field id="Title"/>
                <field id="Hypervisor__c"/>
                <field id="Affected_versions__c"/>
                <field id="Category__c"/>
                <field id="LastPublishedDate"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="Online" enclosevalueinquotes="true" field="PublishStatus"/>
            </conditions>
            <actions/>
        </model>
        <model id="CaseArticle" query="true" createrowifnonefound="false" datasource="salesforce" sobject="CaseArticle">
            <fields>
                <field id="CaseId"/>
                <field id="Case.CaseNumber"/>
                <field id="KnowledgeArticleVersionId"/>
                <field id="KnowledgeArticleVersion.Name"/>
                <field id="ArticleLanguage"/>
                <field id="KnowledgeArticleId"/>
                <field id="KnowledgeArticle.Name"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="SupportProcedure" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-T-_-346">
            <fields>
                <field id="LastPublishedDate" hideable="true" uniqueid="fi-T-_-1554">
                    <label>Published Date</label>
                </field>
                <field id="Title" hideable="true" uniqueid="fi-T-_-467"/>
                <field id="Hypervisor__c" hideable="true" uniqueid="fi-T-_-787"/>
                <field id="Affected_versions__c" hideable="true" uniqueid="fi-T-_-798"/>
                <field id="Category__c" hideable="true" uniqueid="fi-T-_-816"/>
            </fields>
            <rowactions/>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
            <filters/>
        </skootable>
        <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="true" model="CaseArticle" buttonposition="" mode="read" allowcolumnreordering="true" responsive="true" uniqueid="sk-YKD-848">
            <fields>
                <field id="CaseId" hideable="true" uniqueid="fi-YKD-867"/>
                <field id="Case.CaseNumber" hideable="true" uniqueid="fi-YKD-876"/>
                <field id="KnowledgeArticleVersionId" hideable="true" uniqueid="fi-YKD-886"/>
                <field type="COMBO" hideable="true" uniqueid="fi-YKD-940">
                    <label>Template Field</label>
                    <template>{{{KnowledgeArticleVersionId}}}</template>
                </field>
                <field id="KnowledgeArticleId" hideable="true" uniqueid="fi-YKD-1017"/>
                <field type="COMBO" hideable="true" uniqueid="fi-YKD-1028">
                    <label>Another Template Field</label>
                    <template>{{{KnowledgeArticleId}}}</template>
                </field>
                <field id="KnowledgeArticleVersion.Name" hideable="true" uniqueid="fi-YKD-895"/>
                <field id="ArticleLanguage" hideable="true" uniqueid="fi-YKD-905"/>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
        <actionsequences uniqueid="sk-T-_-377"/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Korey

Korey

  • 1,108 Points 1k badge 2x thumb

Posted 5 months ago

  • 1
Photo of Korey

Korey

  • 1,108 Points 1k badge 2x thumb
I was able to get this working without code. I basically just needed to create a new CaseArticle and set the conditions of the model to a Case ID, the Knowledge Article Version Id, and a Knowledge Article Id then save the model. 

One thing of note is that I am still not sure why I cannot "Display" the Ids without adding the third  {{{curly bracket}}}, but it isn't needed when creating the new CaseArticle.

Here's the XML for anyone else who might need to attach knowledge articles to a case:


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="SupportProcedure" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Support_Procedure__kav">
            <fields>
                <field id="Title"/>
                <field id="Hypervisor__c"/>
                <field id="Affected_versions__c"/>
                <field id="Category__c"/>
                <field id="LastPublishedDate"/>
                <field id="Id"/>
                <field id="KnowledgeArticleId"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="Online" enclosevalueinquotes="true" field="PublishStatus"/>
            </conditions>
            <actions/>
        </model>
        <model id="CaseArticle" query="true" createrowifnonefound="false" datasource="salesforce" sobject="CaseArticle">
            <fields>
                <field id="CaseId"/>
                <field id="Case.CaseNumber"/>
                <field id="KnowledgeArticleVersionId"/>
                <field id="KnowledgeArticleVersion.Name"/>
                <field id="ArticleLanguage"/>
                <field id="KnowledgeArticleId"/>
                <field id="KnowledgeArticle.Name"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model id="NewCaseArticle" query="false" createrowifnonefound="false" datasource="salesforce" sobject="CaseArticle">
            <fields>
                <field id="KnowledgeArticleId"/>
                <field id="KnowledgeArticle.Name"/>
                <field id="CaseId"/>
                <field id="Case.CaseNumber"/>
                <field id="CreatedById"/>
                <field id="CreatedBy.Name"/>
                <field id="KnowledgeArticleVersionId"/>
                <field id="KnowledgeArticleVersion.Name"/>
                <field id="ArticleVersionNumber"/>
                <field id="ArticleLanguage"/>
                <field id="Id"/>
            </fields>
            <conditions>
                <condition type="param" field="CaseId" fieldtargetobjects="Case" inactive="false" value="Id" operator="=" enclosevalueinquotes="true"/>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="KnowledgeArticleId" fieldtargetobjects="Support_Procedure__ka,Technical_Field_Notices__ka" state="filterableoff" inactive="true" name="KnowledgeArticleId"/>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="KnowledgeArticleVersionId" fieldtargetobjects="Support_Procedure__kav,Technical_Field_Notices__kav" state="filterableoff" inactive="true" name="KnowledgeArticleVersionId"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="SupportProcedure" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-T-_-346">
            <fields>
                <field id="LastPublishedDate" hideable="true" uniqueid="fi-T-_-1554">
                    <label>Published Date</label>
                </field>
                <field id="Title" hideable="true" uniqueid="fi-T-_-467"/>
                <field id="Hypervisor__c" hideable="true" uniqueid="fi-T-_-787"/>
                <field id="Affected_versions__c" hideable="true" uniqueid="fi-T-_-798"/>
                <field id="Category__c" hideable="true" uniqueid="fi-T-_-816"/>
                <field id="Id" hideable="true" uniqueid="fi-124Q-1065"/>
                <field id="KnowledgeArticleId" hideable="true" uniqueid="fi-124Q-1076"/>
                <field type="COMBO" hideable="true" uniqueid="fi-124Q-1150">
                    <label>Template Field</label>
                    <template>{{{KnowledgeArticleId}}}</template>
                </field>
            </fields>
            <rowactions>
                <action type="multi" label="Run multiple actions" icon="sk-icon-magic">
                    <actions>
                        <action type="action-sequence" action-sequence-id="453261d4-6c56-492f-b1b2-009351dd6342"/>
                    </actions>
                    <renderconditions logictype="and">
                        <rendercondition type="blank" operator="!=" fieldmodel="SupportProcedure" sourcetype="param" sourceparam="id" value="null" enclosevalueinquotes="false"/>
                    </renderconditions>
                </action>
            </rowactions>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
            <filters/>
            <renderconditions logictype="and"/>
        </skootable>
        <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="true" model="CaseArticle" buttonposition="" mode="read" allowcolumnreordering="true" responsive="true" uniqueid="sk-YKD-848">
            <fields>
                <field id="CaseId" hideable="true" uniqueid="fi-YKD-867"/>
                <field id="Case.CaseNumber" hideable="true" uniqueid="fi-YKD-876"/>
                <field id="KnowledgeArticleVersionId" hideable="true" uniqueid="fi-YKD-886"/>
                <field type="COMBO" hideable="true" uniqueid="fi-YKD-940">
                    <label>Template Field</label>
                    <template>{{{KnowledgeArticleVersionId}}}</template>
                </field>
                <field id="KnowledgeArticleId" hideable="true" uniqueid="fi-YKD-1017"/>
                <field type="COMBO" hideable="true" uniqueid="fi-YKD-1028">
                    <label>Another Template Field</label>
                    <template>{{{KnowledgeArticleId}}}</template>
                </field>
                <field id="KnowledgeArticleVersion.Name" hideable="true" uniqueid="fi-YKD-895"/>
                <field id="ArticleLanguage" hideable="true" uniqueid="fi-YKD-905"/>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
        <actionsequences uniqueid="sk-T-_-377">
            <actionsequence id="453261d4-6c56-492f-b1b2-009351dd6342" label="New Case Article" type="reusable" uniqueid="sk-124Q-1023">
                <actions>
                    <action type="blockUI" message="Attaching"/>
                    <action type="emptyModelData">
                        <models>
                            <model>NewCaseArticle</model>
                        </models>
                    </action>
                    <action type="setCondition" model="NewCaseArticle" condition="KnowledgeArticleVersionId" fieldmodel="NewCaseArticle" affectedrows="context" field="KnowledgeArticleVersionId" fieldtargetobjects="Support_Procedure__kav,Technical_Field_Notices__kav" enclosevalueinquotes="true" value="{{{Id}}}"/>
                    <action type="setCondition" model="NewCaseArticle" condition="KnowledgeArticleId" value="{{{KnowledgeArticleId}}}" fieldmodel="NewCaseArticle" affectedrows="context" field="KnowledgeArticleId" fieldtargetobjects="Support_Procedure__ka,Technical_Field_Notices__ka" enclosevalueinquotes="true"/>
                    <action type="createRow" model="NewCaseArticle" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                        <defaults/>
                    </action>
                    <action type="save" rollbackonanyerror="true">
                        <models>
                            <model>NewCaseArticle</model>
                        </models>
                    </action>
                    <action type="unblockUI"/>
                </actions>
                <description>Attach a Knowledge Article to a Case</description>
                <inputs/>
            </actionsequence>
        </actionsequences>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>