You need to sign in to do that
Don't have an account?
John M
getting error action.SetCallback is not a function
Hi,
I am new to Lightning please help me with this. I am getting the following error:
Uncaught Action failed: c:LinkToAttachment$controller$preview [action.SetCallback is not a function]
when I try to run my lightning component on button click. Please Help
Here is my Code:
LinkToAttachment.cmp
LinkToAttachment.apxc
Thanks
I am new to Lightning please help me with this. I am getting the following error:
Uncaught Action failed: c:LinkToAttachment$controller$preview [action.SetCallback is not a function]
when I try to run my lightning component on button click. Please Help
Here is my Code:
LinkToAttachment.cmp
<aura:component controller = "LinkToAttachment" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" > <aura:attribute name="contentId" type="String" default="0691h0000001LU8AAM"/> <lightning:button variant="brand" label="Quick Reference Guide" onclick="{!c.preview }" /> </aura:component>LinkToAttachmentController.js
({ preview : function(component, event, helper) { var action = cmp.get("c.openfile1"); action.SetCallback(this, function(response){ var state = response.getState(); if(state == "SUCCESS"){ alert("From server: " + response.getReturnValue()); var Cdid = response.getReturnValue(); cmp.set("v.contentId", Cdid); $A.get('e.lightning:openFiles').fire({ recordIds: ["v.contentId"] }); } }); $A.enqueueAction(action); } })
LinkToAttachment.apxc
public with sharing class LinkToAttachment { @AuraEnabled Public static List<ContentDocument> openfile1(){ List<ContentDocument> Cdid=[SELECT id FROM ContentDocument where Title=' Test Document']; return Cdid; } }
Thanks
but your component reference is 'component' not 'cmp'. Try:
Hi,
You are using incorrect variable name 'cmp' and the variable you have passed in your preview function is 'component'.
In your Js controller change lines 3 and 9 to this:
Let me know if it helps.
Thanks
1. As John and Narendra have already hightlighted, you're referring incorrect variable name.
Replace line no. 3 and no. 9 referring "cmp" with "component".
2. The "SetCallback" first character "S" should be in lower case i.e "setCallback".