3

Is it possible to use SS1.0 inside of a SS2.0 file? Are there some annotations I have to add or is it even possible?

Coldstar
  • 1,324
  • 1
  • 12
  • 32
  • 1
    I do not believe this is possible. You *might* be able to get away with it in a Client Script by calling `window.nlapiGetFieldValue` or something like that. I have not tested it. The more important question is, why would you want to do this? – erictgrubaugh May 19 '16 at 19:11
  • You are right, I dont want to do it but you cannot use SS2.0 sublist api without having Advanced Number Inventory Management enabled, which this company doesn't. It does not work without it. Thank you for your reply however – Coldstar May 19 '16 at 22:11
  • Might be something you want to report to NetSuite support – Rusty Shackles May 20 '16 at 00:27

2 Answers2

5

That is not allowed. Please see below excerpts from SuiteAnswers.

https://netsuite.custhelp.com/app/answers/detail/a_id/44630

SuiteScript 2.0 – Getting Started

Version Cohabitation Rules

Your script (entry point script and supporting library scripts) must use either SuiteScript 1.0 or SuiteScript 2.0. You cannot use APIs from both versions in one script.

You can, however, have multiple scripts that use different SuiteScript versions. These can be deployed in the same account, in the same SuiteApp, and on the same record.


https://netsuite.custhelp.com/app/answers/detail/a_id/31709/kw/Suitescript%202.0

Version 2016 Release 1 (2016.1) Release Notes

nlapi/nlobj Prefix Retirement

SuiteScript 2.0 is modeled to look and behave like modern JavaScript. To meet that objective, SuiteScript 2.0 methods and objects are not prefixed with nlapi and nlobj.

This change also reflects the modular organization of SuiteScript 2.0. SuiteScript 1.0 methods and objects respectively belong to the nlapi and nlobj namespaces. SuiteScript 2.0 methods and objects are encapsulated within various modules.

3

We've got a script that needs to update many fields on an Opportunity with many sub-list items. With our script, the 2.0 way of selecting each sub-list item and then calling setCurrentSublistValue() took about 40 seconds to do 59 sub-list items. I used the window.nlapiSetLineItemValue() hack and it takes around 2 seconds.

It's probably not recommended and YMMV, but I did put some checking to see if will work. See my code below...

var canUseLegacyApi = typeof window.nlapiSetLineItemValue === "function";
// Loop the sublist and update
for (var k = 0; (itemCount >= 0) && (k < itemCount); k++) {
    if (!canUseLegacyApi) { // If the Suite Script 1.0 API isn't available, do it the slow way.
        currentRecordOpp.selectLine({
            sublistId: 'item',
            line: k
        })
    }

    if(canUseLegacyApi) {
        // TODO: HACK: Change this total hack once SS2.x supports updating line item values (without doing a 
        // selectLine, which takes too long)
        // NOTE: SS1.0 sub-list calls are 1-based vs SS2.x calls being 0-based. Hence the k+1
        window.nlapiSetLineItemValue('item', 'field_id, k+1, 'new value');
        // Update other fields here...
    } else {
        currentRecordOpp.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'field_id',
            value: 'new value',
            fireSlavingSync: true
        });
        // Update other fields here...
    }

    if(!canUseLegacyApi) {
        currentRecordOpp.commitLine({sublistId: 'item'});
    }

    // TODO: HACK: This is required to re-paint the sublist after the nlapiSetLineItemValue calls. Remove once SS2.x 
    // supports this.
    currentRecordOpp.selectLine({
        sublistId: HVAC_SUBLIST,
        line: 0
    })
}
josh
  • 51
  • 7