Can a variable have the same name as a function pa...
# suitescript
s
Can a variable have the same name as a function parameter?
e
within the function?
Copy code
function tryThis(param){
 console.log(param);
}
tryThis('test') // 'test'

function sameVar(param){
  param = 'changed'
  console.log(param)
}
sameVar('test') // 'changed'
s
Copy code
define(['N/currentRecord', 'N/search', 'N/record'], function (currentRecord, search, record) {
function pageInit(context) {

      var currentRecord = context.currentRecord;
...
  }
}
@ericbirdsall In this way
e
Assuming this is a client script, I don't believe you need to add the 'N/currentRecord' module at all
👍 1
Copy code
define(['N/search', 'N/record'], function (search, record) {
function pageInit(context) {

      var currentRecord = context.currentRecord;
      currentRecord.getValue(...) // this will work
  }
}
👍 1
@Slig
s
@ericbirdsall Thanks! I will try here
But why wouldn't I need to use CurrentRecord in a client script?
e
each available function is actually passed the currentRecord within the script context
Copy code
/**
         * Function to be executed after page is initialized.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord - Current form record
         * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
         *
         * @since 2015.2
         */
        function pageInit(scriptContext) {

        }
👍 1
Copy code
/**
         * Validation function to be executed when record is saved.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord - Current form record
         * @returns {boolean} Return true if record is valid
         *
         * @since 2015.2
         */
        function saveRecord(scriptContext) {

        }
👍 1
Same goes for fieldChanged, postSourcing, etc. etc.
👍 1
s
@ericbirdsall Thanks