This topic contains 9 replies, has 0 voices, and was last updated by pcutler 7 years, 12 months ago.

  • Author
    Posts
  • #1508

    JohnCCole

    How is it possible that when creating a SuiteScript 2.0 Client Script that the 1.0 API is getting loaded?

    When creating new customizations since 2.0’s release I have been making every effort to use 2.0 but this is my first client side script.

    With the conflict of the two API versions being loaded at the same time the 2.0 call’s won’t work. Is anyone else experiencing this?

    For example the following load call of a task works in the Chrome browser console on a task form where I have deployed a 2.0 Client Side script

    Code:
    require([‘N/record’], function(record){var rec = record.load({id:someid,type:’TASK’})
    But the creation of a Task fails and seems related to the presence of the 1.0 API

    Code:
    require([‘N/record’,’N/currentRecord’,’N/runtime’], function(record,currentRecord,runtime){try{ var dt = new Date(); dt.setDate(dt.getDate() + 90);var taskRec = record.create({
    type:’TASK’,isDynamic:true
    });
    taskRec.setValue({fieldId:’customform’,value:87});
    taskRec.setValue({fieldId:’owner’,value:runtime.getCurrentUser().id});
    taskRec.setValue({fieldId:’assigned’,value:runtime.getCurrentUser().id});
    taskRec.setValue({fieldId:’company’,value:currentRecord.get().getValue({fieldId:’company’})});

    // Get the last order date

    taskRec.setValue({fieldId:’duedate’,value:dt});
    taskRec.setValue({fieldId:’startdate’,value:dt});
    taskRec.setValue({fieldId:’status’,value:’NOTSTART’});
    taskRec.setValue({fieldId:’priority’,value:’MEDIUM’});

    taskRec.setValue({fieldId:’custevent_mtg_type’,value:3});
    taskRec.setValue({fieldId:’custevent_mtg_follow_up_type’,value:’2′});
    taskRec.setValue({fieldId:’title’,value:’Customer Follow Up’});

    var taskID = taskRec.save({
    enableSourcing: false,
    ignoreMandatoryFields: true
    });
    console.log(taskID);}catch(ex){console.log(ex.toString());}})
    This is a cached copy. Click here to see the original post.

  • #1509

    david.smith

    SS1.0 is not going away any time soon. The can and do run on the UI and records together (not to be confused with mixing them in the same script).

    Can you explain further because I haven’t run into any conflicts and SS2.0 not working. Maybe post your error or something showing that it’s not working.

  • #1510

    JohnCCole

    The code is posted above. My client side Script 2.0 with no reference to 1.0 API the first block of code works in the Browser console loading a task record. The second block (trying to create) a task record fails with “nlapiGetField(…).isHidden is not a function”

  • #1511

    david.smith

    You cannot run SS2.0 in the console.

  • #1512

    JohnCCole

    I’m sorry but yes you can if you run the below code on a page containing a 2.0 Client Side script this will run in the Chrome Browser Console

    Code:
    require([‘N/record’], function(record){
    var strTaskID = ‘198256’;//replace with a task id in your system
    var rec = record.load({id:strTaskID,type:’TASK’});
    console.log(rec.id);})

  • #1513

    Olivier Gagnon NC

    Hi John,

    Could be several things, but if I had to make a bet, I’d say that what might be happening is that when you submit the record, it triggers all existing scripting deployed on that record. So maybe another script is failing and the error is bubbling up to your submit.

    I would not rule out that, as all scripts are triggered, NS is tripping on SS1.0 and SS2.0 being both loaded as the various scripts try to run. There may be an incompatibility there.

    As a first stab, I would try to undeploy all scripting (and workflows, to be safe) from tasks and see if that works. If it doesn’t, well, you have some unenviable debugging ahead of you, but at least you’ll have direction.

  • #1514

    pcutler

    Hi John, do you want to share what the error is and why you feel like the error is related to SS 1.0? It’s hard to provide suggestions without knowing more about the error. But I can second Oliver’s general debugging strategy, it’s generally a good idea to try to isolate the issue by temporarily disabling other scripts on the same record type.

  • #1515

    JohnCCole

    Originally posted by Olivier Gagnon NC

    View Post

    Hi John,

    Could be several things, but if I had to make a bet, I’d say that what might be happening is that when you submit the record, it triggers all existing scripting deployed on that record. So maybe another script is failing and the error is bubbling up to your submit.

    I would not rule out that, as all scripts are triggered, NS is tripping on SS1.0 and SS2.0 being both loaded as the various scripts try to run. There may be an incompatibility there.

    As a first stab, I would try to undeploy all scripting (and workflows, to be safe) from tasks and see if that works. If it doesn’t, well, you have some unenviable debugging ahead of you, but at least you’ll have direction.

    Oliver this was my first thoughts as well and while there were workflow and ue scripts runnng disabling them ha no affect.

    This was the error

    Code:
    TypeError: nlapiGetField(…).isHidden is not a function”
    1: ” at Error (native)”
    2: ” at Object.createError [as nlapiCreateError] (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:118:29)”
    3: ” at Object.createError [as create] (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:966:42)”
    4: ” at _handleError (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:28039:37)”
    5: ” at runInternalScript (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:27944:25)”
    6: ” at Scope._fieldChange [as fieldChange] (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:28132:25)”
    7: ” at DynamicRecordImpl.triggerFieldChangeScript (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:26318:36)”
    8: ” at Record.triggerFieldChangeScript (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:31810:36)”
    9: ” at DynamicRecordImpl.triggerFieldChangeEvent (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:26201:20)”
    10: ” at Record.triggerFieldChangeEvent (https://system.sandbox.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2016.2.0&minver=79:31801:36)

    So I changed the code to set ignoreFieldChange to true on all setValue calls, and now the record creates a task record in the Chrome Browser Window. Perhaps it’s this weird use case I have where I’m editing one task and when that task is being completed I need to create a new task.

  • #1516

    Olivier Gagnon NC

    Hmm. Something must be failing in core NetSuite code. I’d file a defect (for what that’s worth).

  • #1517

    pcutler

    It looks like you’re creating the task record in dynamic mode. Dynamic mode triggers the FIELD CHANGE event each time you call .setValue(). Have you added logging to isolate which line the script fails on? That could be helpful in determining whether there is a defect or a mistake in your code. For instance, if you’re calling .setValue() for a field that does not exist on the task record then that could be an easy fix, even if it is a poor error message that NetSuite is providing.

You must be logged in to reply to this topic.