0

I am trying to set up Knowledge in a Community, using the Napili template and the Article Detail page template. I just need to be able to show the Title and Article Body fields in the page, and not the Salesforce record details (it should just look like a regular page on a website).

I have tried a few different things to try and get this to work, but I can't figure out how to pass the record ID from the Community page into the Custom Component so that I can use a custom Apex controller to then load the record details. I'm not sure if that is even necessary, or if there is a way to use the Knowledge__kav standard controller?

EDIT 2: I was missing response handling in the JS controller. Here is the updated controller code that solved my problem:

({
    doInit : function(component, event, helper) 
    {
        var actionArticle = component.get("c.getArticle");

        actionArticle.setParams({
            recordId : component.get("v.recordId")
        });

        actionArticle.setCallback(this, function(response) {
            component.set("v.Article", response.getReturnValue());
        })

        console.log('>> ' + component.get("v.recordId"));
        $A.enqueueAction(actionArticle);


    }
})

EDIT: This is where my files ended up, so there's a combination of the different methods I tried in here.

Component:

<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" controller="ArticleContentView_Controller">
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="Article" type="Knowledge__kav" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <ui:outputText value="{!v.Article.Article_Body__c}" />
</aura:component>

JS Controller:

({
    doInit : function(component, event, helper) 
    {
        var actionArticle = component.get("c.getArticle");

        actionArticle.setParams({
            recordId : component.get("v.recordId")
        });

        $A.enqueueAction(actionArticle);
    }
})

Apex Controller:

public with sharing class ArticleContentView_Controller 
{
    //public String articleId {get; set;}

    @AuraEnabled
    public static Knowledge__kav getArticle(ID recordId)
    {
        Knowledge__kav article = [SELECT Id, Article_Body__c FROM Knowledge__kav WHERE Id = :recordId LIMIT 1]; 
        return article;
    }
}
  • can you update your post with how you are attempting to do so, component markup, JS controller anad apex controller? and no, you cant leverage standardControllers in lightning. – glls Mar 13 '18 at 20:31
  • fyi: if you are using an object record page, you can use the recordId attribute if you have implemented force:hasRecordId in your component – glls Mar 13 '18 at 20:38
  • @glls I have updated the post with the code that I have tried so far. It's a bit of a mix of everything I've tried unfortunately, as I used the same files each time I tried something new – dropZero Mar 13 '18 at 20:51
  • 1
    ahh, well I missed something, you arent handling the server response =P (as far as i can see, your enqueing the action, however, dont do nothing afterwards – glls Mar 14 '18 at 17:35
  • 1
    when you add your server response hadnling on success, you should bind it to your article attribute – glls Mar 14 '18 at 17:36
1

As originally stated, you werent handling the server response, thus not assigning anything to your Article Attribute in the Client Controller (as far as i can see, you were enqueing the action, however, not doing anything afterwards)

Once you have done so, make sure you set the response and bind it tou your knwoledge attribute.

Additionally, you might want to consider error handing on your client side controller

Salesforce's documentation does a good job at providing example snippets for you to do so Calling a Server-Side Action

0

After reading through the commuinty and stackexchange cases, our Salesforce Admin actually ended up implementing this alternative solution:

"(Worried about how displaying articles in a custom component would affect our view statistics and ability to turn on voting). I am sure all of that can be coded around, but then it would have become a much bigger undertaking. Eventually what I settled on was some CSS to hide the title and url name:

article.content .forcePageBlockSectionRow ~ .forcePageBlockSectionRow{ display:none; }

This is a bit of a hack - it just hides everything but the first field in the article. So if we just use this, then articles should only have one publicly available field, which I think is okay for our purposes. Otherwise, we will need to create a custom component. We also always need page layouts to show the article body first.

I also took the liberty of adding some more CSS to hide some things I think we don't want:

Hide the field label ("Article Body")
.test-id__field-label{ display:none; }

Hide the login/username and profile info (I am hiding the stuff inside the div because otherwise it messes with the position of the search bar) .cProfileCon > div{ display:none; }

The CSS is in the theme section, Colors>Edit CSS"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.