0

My overall goal is to export my component data to a format that I can save it. I found this article (https://cloudmatters.blog/2018/11/04/lighting-out-visualforce-lightning-printing/) and was trying to implement it.

I branched off from this as I was having problems and was trying to simply get my component to appear in a visualforce page as a first step.

Before starting this, my component was/is called from a button with the following link: /lightning/n/Group_Structures_List?//Aid={! Account.Id }&//Tid=123456789

In the components DoInit, I pull the account ID which I then use to pull the records for that account id.

Here is the code from the Doinit on the component:

doInit : function(component, event, helper) {
   console.log('### Im in DoInit');

////only use url if the Aid is not already populated 
    if(!Aid){ 
        //console.log('### Im in the if statement coming from account and here is the window.location ' + window.location.search.split('//')[1]);
    //get the url and split so you get the aid id that is being passed
    var URLAid = window.location.search.split('//')[1];
        console.log('### here is URLAid ' + URLAid);
 //pull only the actual Account ID
     var Aid = URLAid.substring(4,19);
    } 
console.log('### here is the Aid ' + Aid);
//set the Aid attribute on the component so it can be passed to the apex class through the helper
     component.set("v.Aid", Aid);

    // Retrieve group structure values during component initialization
        helper.loadGroupStructures(component);
        helper.loadGroupNumbers(component);
        helper.loadSections(component);
        helper.loadPackages(component);
        helper.loadProducts(component);
        helper.updateTotal(component);

},

I then added a button to the component to open it up in lighting. (again, with the intent of eventually having this display in a printable format) But when I use that button, I get the following message: This page has an error. You might just need to refresh it. Action failed: c:GroupStructuresList$controller$doInit [Cannot read property 'substring' of undefined] Failing descriptor: {c:GroupStructuresList$controller$doInit}

Obviously, I am not populating Aid correctly so that it can be used. Any help would be greatly appreciated!!! Here are the pieces I'm using to launch the VF page with the component embedded:

Here is the app which is named GroupStructureListPrint:


Here is the Visualforce Page named GropuStructureListPrint:

<apex:page >
<apex:includeLightning />

<script>
    $Lightning.use("c:GroupStructureListPrint", function() {
      $Lightning.createComponent("c:GroupStructuresList",
      {},
      "lightning",
      function(cmp) {
        // do some stuff
          console.log('This message is from visualforce function');
        console.log('Data which is coming from lightning component',event.getParam('data'));
        debugger;
      });
    });
</script> 

Here is the function from the component to open it:

 PrintPageAction : function(component, event, helper) {
var url = location.origin + '/apex/GroupStructureListPrint?//Aid=' 
     + component.get("v.Aid")
    ; 
window.open(url, '_self');
},

Thank you!!!

Fred

0

You can pass the data while creating the component, say you have paramater named Aid, and you want to pass it to the component.

 <script> $Lightning.use("c:GroupStructureListPrint", function() { $Lightning.createComponent("c:GroupStructuresList",
 { Aid : "{!$currentpage.parameters.Aid}"}, "lightning", function(cmp) {
 // do some stuff console.log('This message is from visualforce function');
 console.log('Data which is coming from lightning component',event.getParam('data'));
 debugger;
 });
 }); 
</script> 

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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