0
votes

We are trying in a RESTLet to access the sublist "demandplandetail" from a NetSuite Item Demand Plan. Everything goes fine until a certain point. We are able to load it and process the demandplan for 2020. However, here it gets frustrating.

We know (can see from NetSuite) that there is data also for 2021. However, to access that from SuiteScript seems very difficult.

1st solution) The item demand plan has the field "year". OK, just set that to 2021, save and reload the record. Result: saving ignored, year still is 2020.

2nd solution) Set the year using a Date object as in:

var demandPlan = record.load(...)
var d = new Date();
    demandPlan.setValue({
    fieldId: 'year',
    value: d
});

Gives the following: :"TypeError: Cannot find function getFullYear in object NaN. (NLRecordScripting.scriptInit$lib#59)","stack":["setDatesForMonthAndYear(NLRecordScripting.scriptInit:108)","anonymous(N/serverRecordService)"

on saving the record. I also get the same using (various) strings adhering to acceptable date formats (as in '1/1/2021'). I have also tried the format package giving me a date string -> the same result.

Also read somewhere that you may need to set the start date (field 'startdate') in the record. Tried several variations but it stubbornly refuses :(.

Wonder if anyone has seen anything similar?

Best Regards, Toni

2

2 Answers

0
votes

Hi Please try the below code also check if you're passing date object to the field not the date string.

    function formatDate() {
        
        var dateROBD = format.parse({
            value: new Date(),
            type: format.Type.DATE
        });
        
        // this line optional if you want to try with or else ignore this
        dateROBD = convertUTCDateToLocalDate(new Date(dateROBD));

        return dateROBD;
    }

    function convertUTCDateToLocalDate(date) {
        var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);

        var offset = date.getTimezoneOffset() / 60;
        var hours = date.getHours();

        newDate.setHours(hours - offset);

        return newDate;
    }
0
votes

OK, mystery solved. Turned out that this is not supported in SuiteScript 2.0 but you need to use 1.0.