AnsweredAssumed Answered

Share a function between record.js and create.js

Question asked by Kenneth Brill on Dec 12, 2017
Latest reply on Dec 15, 2017 by Kenneth Brill

This should be easy but I can't make it work, I just want to share functions between create and record so I dont have to repeat code.

 

I have a JS Grouping File

<?php
//Loop through the groupings to find grouping file you want to append to
foreach ($js_groupings as $key => $groupings) {
     foreach ($groupings as $file => $target) {
          //if the target grouping is found
          if ($target == 'include/javascript/sugar_grp7.min.js') {
               //append the custom JavaScript file
               $js_groupings[$key]['custom/modules/Cases/clients/base/views/shared/casesShared.js'] = 'include/javascript/sugar_grp7.min.js';
          }
          break;
     }
}

and I have a JS file (custom/modules/Cases/clients/base/views/shared/casesShared.js)

 

     /**
      * Shared Cases JavaScript
      */

     this.updateCasesCallBackInfo = function() {
          var customerContactName = this.model.get('in_customer_contacts_cases_1_name');
          var customerContactID = this.model.get('in_customer_contacts_cases_1in_customer_contacts_ida');
          var customerContactPhone = this.model.get('customer_contact_phone_numbe_c');
          var partnerContactName = this.model.get('contacts_cases_1_name');
          var partnerContactID = this.model.get('contacts_cases_1contacts_ida');
          var partnerContactPhone = this.model.get('partner_contact_phone_number_c');
          var callBackName = '';
          var callBackNumber = '';
          if (partnerContactName != '') {
               var nameArray = [partnerContactName, customerContactName];
          } else {
               var nameArray = [customerContactName];
          }
          if (partnerContactPhone != '') {
               var phoneArray = [partnerContactPhone, customerContactPhone];
          } else {
               var phoneArray = [customerContactPhone];
          }
          callBackName = (nameArray.join() != ',' ? nameArray.join() : '');
          callBackNumber = (phoneArray.join() != ',' ? phoneArray.join() : '');
          self.model.set('call_back_name_c', callBackName);
          sessionStorage.setItem('call_back_name_c', callBackName);
          self.model.set('call_back_number_c', callBackNumber);
          sessionStorage.setItem('call_back_number_c', callBackNumber);
     }

I would like to call that function from either record.js or create.js in Cases.  I have tried instantiating the function every way I can think of

function updateCasesCallBackInfo()

updateCasesCallBackInfo: function() {

//ect..

but when I try to call it I get

 

TypeError: self.updateCasesCallBackInfo is not a function. (In 'this.updateCasesCallBackInfo()', 'this.updateCasesCallBackInfo' is undefined)

Outcomes