``` function postSourcing(scriptContext) { ...
# suitescript
n
Copy code
function postSourcing(scriptContext) {

      try {
        var currentRecord = scriptContext.currentRecord;
        var fieldchanged = scriptContext.fieldId;

        if (fieldchanged == "customer") {
          var cusid = currentRecord.getValue({fieldId: 'customer'});
          if (cusid != null && cusid != "") {
            var url = url.resolveScript({
              scriptId: 'customscript_load_invoice_groups',
              deploymentId: 'customdeploy_load_invoice_groups',
              returnExternalUrl: false,
              params: {
                  cusid: cusid
                }
            });
            addSublistValues(currentRecord, cusid);
          } else {
            var lines = currentRecord.getLineCount({sublistId: 'recmachcustrecordpayment_parent'});
            for (var i = lines - 1; i >= 0; i--) {
              log.debug('looping on line: ', i);
              currentRecord.removeLine({sublistId: 'recmachcustrecordpayment_parent', line: i, ignoreRecalc: true});
          }
          }
        }

      } catch (e) {
        log.debug('Error reads: ', e.name + e.message);
      }
  }
I am trying to pass a parameter to a suitelet from a client script - I am getting this error: TypeErrorCannot read properties of undefined (reading 'resolveScript')
e
I think the problem is with
url
- can you share your define statement?
n
url is just supposed to use the N/url module
e
but you are resetting url in this line!
Copy code
var url = url.resolveScript(
may have something to do with it
n
gotcha
even if I change var url = url.resolveScript to something like var testurl = url.resolveScript it doesn't work
s
avoid accidental reassignment by using
const
n
what if I just remove the first part and just do url.resolveScript
s
be be sure you did something like
import * as url from 'N/url'
n
im just trying to pass a parameter to a suitelet
s
other than that, according to the docs,
resolveScript
is only available for server-side scripts.
n
hmm
interesting because it works in pageInit in client side script
maybe it only works on certain entry points
a workaround would be to just formulate the url yourself
n
yeah I mean maybe i'm not using the right thing but I want to pass a value to a suitelet
a
I think the issue with the code is that the param keys need to be quoted
Copy code
params: {
    'cusid': cusid
}
ablobthinking 1
s
they should only need to be quoted if they are not valid JS identifiers without the quotes, unless I'm missing something fundamental?