简体   繁体   中英

NetSuite: Using SUITESCRIPT 1.0 inside of SUITESCRIPT 2.0

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?

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.

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
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM