TypeError: Cannot read property 'split' of undefin...
# suitescript
j
TypeError: Cannot read property 'split' of undefined
Copy code
var arraydate = initdate.split("-")
any idea why? I've checked documentation on split() and being used properly. Also, this is only happening in SB and not in Production, we just refreshed so environments are pretty much the same.
c
Looks like
initdate
is undefined. Log it and see
j
I did that and it comes empty. This script was written by a consultant and what bugs me is that it only happens in Sandbox
c
Ok, so show us the code where
initdate
is set?
j
right above it.
Copy code
var initdate = context["59"]
log.debug({
    title: 'Date',
    details: initdate
});
var arraydate = initdate.split("-")
the value comes from a field in a wordpress website, that's why the 59
it goes through a middleware and then into NetSuite.
c
ok, so is
context
set?
j
Copy code
**
 *@NApiVersion 2.1
 *@NScriptType Restlet
 */

// Script to handle incoming data from the website and create SQT opportunity based records
define(["N/record", "N/search"], function (record, search) {
    // POST the record
    function post(context) {

        // Title Case
        String.prototype.toProperCase = function () {
            return this.replace(/\w\S*/g, function (txt) {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        };

        // Define the variables being captured
        var days = context["57"];
        var package = context["56"];
        var firstname = context["19"];
        var lastname = context["20"];
        var email = context["2"];
        var addressOne = context["58.1"];
        var addressTwo = context["58.2"];
        var city = context["58.3"];
        var state = context["58.4"];
        var zip = context["58.5"];
        var county = context["58.6"];
        var company = context["4"];
        var phone = context["52"];
        var notes = context["51"];
        var leadsource = context["94"];

        // Date time variables (Due date should be 3 days prior to start date)
        var initdate = context["59"]
        log.debug({
            title: 'Date',
            details: initdate
        });
        var arraydate = initdate.split("-")
        var dateString = arraydate[1] + "/" + arraydate[2] + "/" + arraydate[0]

        var duedate = new Date(dateString)
        duedate.setDate(duedate.getDate() - 3)
        var date = new Date(dateString)
e
Log out the value of context. I suspect you’re not getting anything passed in. Typically you would pass in fields to the Restlet with formdata or a query string.