0

I'm trying to host a canvas app on a Lightning page. The canvas app itself needs the current record and type in order to load things on my own server properly. I have the canvas app up and working (decrypting the SignedRequest), but the parameters aren't passed in. Its driving me bonkers.

What seems real funny is if I call cmp.set("foo", "bar"), then calling cmp.get("foo") returns undefined.

Can anyone help figure out what's going on? Why isn't cmp.set() working? Or is that a red herring, and I have something wrong in my .cmp?

Here's my current code, debug stuff and all.

component.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  
    Parameters: <ui:outputText value="{!v.nowork}" />
    
    <force:canvasApp applicationName="My Magical App"
                     developerName="My_Magical_App" 
                     parameters="{!v.parameters}"
                     width="100%"
                     />

</aura:component>

controller.js

({
     doInit : function(cmp) {
        //var parameters = '{"objectId":"' + component.get("v.recordId") + '", "objectType":"' + component.get("v.sObjectName") + '"}';
         
        var recordId = cmp.get("v.recordId");
        var objectType = cmp.get("v.sObjectName");
        
         var json = JSON.stringify({
             recordId: recordId,
             objectType: objectType
         });
         
         alert(json);
         
        cmp.set("v.nowork", "hi mom");
        cmp.set("v.parameters", json);
        cmp.set("v.label","This is a label");
        var label = cmp.get("v.label");

        alert(label);
    }
})

2 Answers 2

2

As written, I'd expect an error to happen early. You can't write to an attribute you don't have access to, and this can cause exceptions.

cmp.set("v.nowork", "hi mom");

I don't see an attribute called nowork, so I expect this line to be the culprit. Make sure you're only setting attributes that are defined in your markup, or if in a related component, that is at least "public" (within your own code) or "global" (within someone else's namespace).

Similarly, doing cmp.set("foo", "bar") would also fail, because there's no Value Provider called "foo" that would provide a default key. You need to be very careful about which value providers you're accessing (c, v, $Label, etc).

0
0

Points to @sfdcfox for the high level answer, but to make it painfully, explicitly clear to others like me who don't eat, breathe, and poop Salesforce:

You must declare an attribute for any "local" variables you use. In my component I had to add this:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName" 
                access="global" >
    
    <aura:attribute name="parameters" type="String" />    <!-- Declare parameters! -->

Now I can access it via cmp.get('v.parameters'); and cmp.set('v.parameters', 'Fizz buzz!');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .