Can't call helper function from helper inside list forEachui:inputDate rendering issue in visualforceunable to fetch the value of dynamically generated component in client side controller of Lightning ComponentLightning component: Child rows in data tableCould not update lightning components: Cannot read property 'Id' of undefinedAre Address fields are restricted to save in LDS?Show checkbox while loading componentHow to pass Date to Datatime lightning inputfieldHow to apply event listener (keypress) only in current component?Create and Navigate to an Account record Detail PageComponent call another lightning component

What is the AI assistant for the Iron Man Rescue armor?

How to create quantum circuits from scratch

How to pass array of values in lualatex?

How to check if all my faces on mesh are all quads using a script

Has Iron Man made any suit for underwater combat?

Is it better to merge "often" or only after completion do a big merge of feature branches?

Why Lie algebras if what we care about in physics are groups?

Why does airflow separate from the wing during stall?

Trivial non-dark twist in dark fantasy

Monday's Blocking Donimoes Problem

Why are Oscar, India, and X-Ray (O, I, and X) not used as taxiway identifiers?

Can a warlock shoot multiple beams from the Eldritch Blast cantrip with only a single free hand?

What do Unicorns want?

Considerations when providing money to only one child out of two

Host telling me to cancel my booking in exchange for a discount?

Found old paper shares of Motorola Inc that has since been broken up

What would be the effects of (relatively) widespread precognition on the stock market?

Why is there an extra "t" in Lemmatization?

Book in which the "mountain" in the distance was a hole in the flat world

How did pilots avoid thunderstorms and related weather before “reliable” airborne weather radar was introduced on airliners?

How do you structure large embedded projects?

Is it ethical to tell my teaching assistant that I like him?

How old is the Italian word "malandrino"?

Can the caster of Time Stop still use their bonus action or reaction?



Can't call helper function from helper inside list forEach


ui:inputDate rendering issue in visualforceunable to fetch the value of dynamically generated component in client side controller of Lightning ComponentLightning component: Child rows in data tableCould not update lightning components: Cannot read property 'Id' of undefinedAre Address fields are restricted to save in LDS?Show checkbox while loading componentHow to pass Date to Datatime lightning inputfieldHow to apply event listener (keypress) only in current component?Create and Navigate to an Account record Detail PageComponent call another lightning component






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have the following code:



setDataTG : function(component)
var data = [], tgdata = [], current, row, picklistMAP = component.get("v.picklistMAP"), dataComplex = component.get("v.dataComplex");
dataComplex.forEach(function(d)
row = ;
//Parse data
if(d.hasOwnProperty('neOrderItem'))
current = d.neOrderItem;
Object.keys(current).forEach(function(k)
if(k === 'NE__ProdName__c')
row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

else if(k === 'NE__Status__c')
row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

else
row[k] = current[k];

);

//Check children
if(d.hasOwnProperty('children'))
data["_children"] = this.setDataTGChildrenHelper(component, d.children);

data.push(row)
tgdata.push(row);
);
console.log('****complex: ' + JSON.stringify(data));
component.set("v.data", data);
component.set("v.tgdata", tgdata);
component.set("v.isLoading", false);
,


And it's not letting me call setDataTGChildrenHelper giving me the following error:



[Cannot read property 'setDataTGChildrenHelper' of undefined]


How can I fix this?










share|improve this question




























    1















    I have the following code:



    setDataTG : function(component)
    var data = [], tgdata = [], current, row, picklistMAP = component.get("v.picklistMAP"), dataComplex = component.get("v.dataComplex");
    dataComplex.forEach(function(d)
    row = ;
    //Parse data
    if(d.hasOwnProperty('neOrderItem'))
    current = d.neOrderItem;
    Object.keys(current).forEach(function(k)
    if(k === 'NE__ProdName__c')
    row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

    else if(k === 'NE__Status__c')
    row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

    else
    row[k] = current[k];

    );

    //Check children
    if(d.hasOwnProperty('children'))
    data["_children"] = this.setDataTGChildrenHelper(component, d.children);

    data.push(row)
    tgdata.push(row);
    );
    console.log('****complex: ' + JSON.stringify(data));
    component.set("v.data", data);
    component.set("v.tgdata", tgdata);
    component.set("v.isLoading", false);
    ,


    And it's not letting me call setDataTGChildrenHelper giving me the following error:



    [Cannot read property 'setDataTGChildrenHelper' of undefined]


    How can I fix this?










    share|improve this question
























      1












      1








      1








      I have the following code:



      setDataTG : function(component)
      var data = [], tgdata = [], current, row, picklistMAP = component.get("v.picklistMAP"), dataComplex = component.get("v.dataComplex");
      dataComplex.forEach(function(d)
      row = ;
      //Parse data
      if(d.hasOwnProperty('neOrderItem'))
      current = d.neOrderItem;
      Object.keys(current).forEach(function(k)
      if(k === 'NE__ProdName__c')
      row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

      else if(k === 'NE__Status__c')
      row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

      else
      row[k] = current[k];

      );

      //Check children
      if(d.hasOwnProperty('children'))
      data["_children"] = this.setDataTGChildrenHelper(component, d.children);

      data.push(row)
      tgdata.push(row);
      );
      console.log('****complex: ' + JSON.stringify(data));
      component.set("v.data", data);
      component.set("v.tgdata", tgdata);
      component.set("v.isLoading", false);
      ,


      And it's not letting me call setDataTGChildrenHelper giving me the following error:



      [Cannot read property 'setDataTGChildrenHelper' of undefined]


      How can I fix this?










      share|improve this question














      I have the following code:



      setDataTG : function(component)
      var data = [], tgdata = [], current, row, picklistMAP = component.get("v.picklistMAP"), dataComplex = component.get("v.dataComplex");
      dataComplex.forEach(function(d)
      row = ;
      //Parse data
      if(d.hasOwnProperty('neOrderItem'))
      current = d.neOrderItem;
      Object.keys(current).forEach(function(k)
      if(k === 'NE__ProdName__c')
      row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

      else if(k === 'NE__Status__c')
      row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

      else
      row[k] = current[k];

      );

      //Check children
      if(d.hasOwnProperty('children'))
      data["_children"] = this.setDataTGChildrenHelper(component, d.children);

      data.push(row)
      tgdata.push(row);
      );
      console.log('****complex: ' + JSON.stringify(data));
      component.set("v.data", data);
      component.set("v.tgdata", tgdata);
      component.set("v.isLoading", false);
      ,


      And it's not letting me call setDataTGChildrenHelper giving me the following error:



      [Cannot read property 'setDataTGChildrenHelper' of undefined]


      How can I fix this?







      lightning-aura-components lightning event






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      molinetmolinet

      927 bronze badges




      927 bronze badges




















          4 Answers
          4






          active

          oldest

          votes


















          4














          This is the case of lexical scoping. You limiting the scope of callback function by using function(). Instead change it to below:



          dataComplex.forEach((d) => {


          Arrow function does'nt has its own scope and so will get the scope of parent object.






          share|improve this answer








          New contributor



          salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


























            0














            Or you can use .bind(this);



             dataComplex.forEach(function(d)
            row = ;
            //Parse data
            if(d.hasOwnProperty('neOrderItem'))
            current = d.neOrderItem;
            Object.keys(current).forEach(function(k)
            if(k === 'NE__ProdName__c')
            row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

            else if(k === 'NE__Status__c')
            row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

            else
            row[k] = current[k];

            ).bind(this);

            //Check children
            if(d.hasOwnProperty('children'))
            data["_children"] = this.setDataTGChildrenHelper(component, d.children);

            data.push(row)
            tgdata.push(row);
            ).bind(this);





            share|improve this answer






























              0














              You can pass helper parameter into each helper function and thus you can call one helper function from another.



              Example: helper1: function(component, event, helper)
              this.helper2();
              ,



              helper2:function(component, event, helper)
              //helper 2 logic here






              share|improve this answer








              New contributor



              Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.


























                0














                A simple and fairly easy to understand approach is to just alias this. The upshot is this approach still works if you have to support IE11.



                const that = this;
                someCollection.forEach(function (element)
                that.otherHelper();
                )





                share|improve this answer

























                  Your Answer








                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "459"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270372%2fcant-call-helper-function-from-helper-inside-list-foreach%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  4














                  This is the case of lexical scoping. You limiting the scope of callback function by using function(). Instead change it to below:



                  dataComplex.forEach((d) => {


                  Arrow function does'nt has its own scope and so will get the scope of parent object.






                  share|improve this answer








                  New contributor



                  salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.























                    4














                    This is the case of lexical scoping. You limiting the scope of callback function by using function(). Instead change it to below:



                    dataComplex.forEach((d) => {


                    Arrow function does'nt has its own scope and so will get the scope of parent object.






                    share|improve this answer








                    New contributor



                    salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





















                      4












                      4








                      4







                      This is the case of lexical scoping. You limiting the scope of callback function by using function(). Instead change it to below:



                      dataComplex.forEach((d) => {


                      Arrow function does'nt has its own scope and so will get the scope of parent object.






                      share|improve this answer








                      New contributor



                      salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      This is the case of lexical scoping. You limiting the scope of callback function by using function(). Instead change it to below:



                      dataComplex.forEach((d) => {


                      Arrow function does'nt has its own scope and so will get the scope of parent object.







                      share|improve this answer








                      New contributor



                      salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.








                      share|improve this answer



                      share|improve this answer






                      New contributor



                      salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.








                      answered 9 hours ago









                      salesforcesassalesforcesas

                      59211 bronze badges




                      59211 bronze badges




                      New contributor



                      salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.




                      New contributor




                      salesforcesas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                          0














                          Or you can use .bind(this);



                           dataComplex.forEach(function(d)
                          row = ;
                          //Parse data
                          if(d.hasOwnProperty('neOrderItem'))
                          current = d.neOrderItem;
                          Object.keys(current).forEach(function(k)
                          if(k === 'NE__ProdName__c')
                          row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

                          else if(k === 'NE__Status__c')
                          row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

                          else
                          row[k] = current[k];

                          ).bind(this);

                          //Check children
                          if(d.hasOwnProperty('children'))
                          data["_children"] = this.setDataTGChildrenHelper(component, d.children);

                          data.push(row)
                          tgdata.push(row);
                          ).bind(this);





                          share|improve this answer



























                            0














                            Or you can use .bind(this);



                             dataComplex.forEach(function(d)
                            row = ;
                            //Parse data
                            if(d.hasOwnProperty('neOrderItem'))
                            current = d.neOrderItem;
                            Object.keys(current).forEach(function(k)
                            if(k === 'NE__ProdName__c')
                            row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

                            else if(k === 'NE__Status__c')
                            row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

                            else
                            row[k] = current[k];

                            ).bind(this);

                            //Check children
                            if(d.hasOwnProperty('children'))
                            data["_children"] = this.setDataTGChildrenHelper(component, d.children);

                            data.push(row)
                            tgdata.push(row);
                            ).bind(this);





                            share|improve this answer

























                              0












                              0








                              0







                              Or you can use .bind(this);



                               dataComplex.forEach(function(d)
                              row = ;
                              //Parse data
                              if(d.hasOwnProperty('neOrderItem'))
                              current = d.neOrderItem;
                              Object.keys(current).forEach(function(k)
                              if(k === 'NE__ProdName__c')
                              row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

                              else if(k === 'NE__Status__c')
                              row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

                              else
                              row[k] = current[k];

                              ).bind(this);

                              //Check children
                              if(d.hasOwnProperty('children'))
                              data["_children"] = this.setDataTGChildrenHelper(component, d.children);

                              data.push(row)
                              tgdata.push(row);
                              ).bind(this);





                              share|improve this answer













                              Or you can use .bind(this);



                               dataComplex.forEach(function(d)
                              row = ;
                              //Parse data
                              if(d.hasOwnProperty('neOrderItem'))
                              current = d.neOrderItem;
                              Object.keys(current).forEach(function(k)
                              if(k === 'NE__ProdName__c')
                              row['NE__ProdName__c'] = current['Name'] + ' - ' + current['NE__ProdName__c'];

                              else if(k === 'NE__Status__c')
                              row['NE__Status__c'] = picklistMAP[current['NE__Status__c']];

                              else
                              row[k] = current[k];

                              ).bind(this);

                              //Check children
                              if(d.hasOwnProperty('children'))
                              data["_children"] = this.setDataTGChildrenHelper(component, d.children);

                              data.push(row)
                              tgdata.push(row);
                              ).bind(this);






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 8 hours ago









                              Pranay JaiswalPranay Jaiswal

                              22.6k5 gold badges33 silver badges73 bronze badges




                              22.6k5 gold badges33 silver badges73 bronze badges





















                                  0














                                  You can pass helper parameter into each helper function and thus you can call one helper function from another.



                                  Example: helper1: function(component, event, helper)
                                  this.helper2();
                                  ,



                                  helper2:function(component, event, helper)
                                  //helper 2 logic here






                                  share|improve this answer








                                  New contributor



                                  Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.























                                    0














                                    You can pass helper parameter into each helper function and thus you can call one helper function from another.



                                    Example: helper1: function(component, event, helper)
                                    this.helper2();
                                    ,



                                    helper2:function(component, event, helper)
                                    //helper 2 logic here






                                    share|improve this answer








                                    New contributor



                                    Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





















                                      0












                                      0








                                      0







                                      You can pass helper parameter into each helper function and thus you can call one helper function from another.



                                      Example: helper1: function(component, event, helper)
                                      this.helper2();
                                      ,



                                      helper2:function(component, event, helper)
                                      //helper 2 logic here






                                      share|improve this answer








                                      New contributor



                                      Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      You can pass helper parameter into each helper function and thus you can call one helper function from another.



                                      Example: helper1: function(component, event, helper)
                                      this.helper2();
                                      ,



                                      helper2:function(component, event, helper)
                                      //helper 2 logic here







                                      share|improve this answer








                                      New contributor



                                      Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.








                                      share|improve this answer



                                      share|improve this answer






                                      New contributor



                                      Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.








                                      answered 7 hours ago









                                      Manjunatha V PManjunatha V P

                                      7




                                      7




                                      New contributor



                                      Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.




                                      New contributor




                                      Manjunatha V P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.























                                          0














                                          A simple and fairly easy to understand approach is to just alias this. The upshot is this approach still works if you have to support IE11.



                                          const that = this;
                                          someCollection.forEach(function (element)
                                          that.otherHelper();
                                          )





                                          share|improve this answer



























                                            0














                                            A simple and fairly easy to understand approach is to just alias this. The upshot is this approach still works if you have to support IE11.



                                            const that = this;
                                            someCollection.forEach(function (element)
                                            that.otherHelper();
                                            )





                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              A simple and fairly easy to understand approach is to just alias this. The upshot is this approach still works if you have to support IE11.



                                              const that = this;
                                              someCollection.forEach(function (element)
                                              that.otherHelper();
                                              )





                                              share|improve this answer













                                              A simple and fairly easy to understand approach is to just alias this. The upshot is this approach still works if you have to support IE11.



                                              const that = this;
                                              someCollection.forEach(function (element)
                                              that.otherHelper();
                                              )






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 7 hours ago









                                              Adrian LarsonAdrian Larson

                                              114k19 gold badges132 silver badges271 bronze badges




                                              114k19 gold badges132 silver badges271 bronze badges



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Salesforce Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f270372%2fcant-call-helper-function-from-helper-inside-list-foreach%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                                  Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                                  François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480