首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Netsuite RESTlet

Netsuite RESTlet
EN

Stack Overflow用户
提问于 2021-05-16 13:34:26
回答 1查看 176关注 0票数 0

可以检索、删除或创建的Netsuite RESTlet示例

有人能从理论上给我解释一下这段代码到底是做什么的吗?

参考:https://tstdrv2433299.app.netsuite.com/app/help/helpcenter.nl?fid=section_4634148062.html

代码语言:javascript
复制
/**
 *@NApiVersion 2.x
 *@NScriptType Restlet
 */
define(['N/record', 'N/error'],
        function(record, error) {
    function doValidation(args, argNames, methodName) {
        for (var i = 0; i < args.length; i++)
            if (!args[i] && args[i] !== 0)
                throw error.create({
                    name: 'MISSING_REQ_ARG',
                    message: 'Missing a required argument: [' + argNames[i] + '] for method: ' + methodName
                });
    }
    // Get a standard NetSuite record
    function _get(context) {
        doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'GET');
        return JSON.stringify(record.load({
            type: context.recordtype,
            id: context.id
        }));
    }
    // Delete a standard NetSuite record
    function _delete(context) {
        doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'DELETE');
        record.delete({
            type: context.recordtype,
            id: context.id
        });
        return String(context.id);
    }
    // Create a NetSuite record from request params
    function post(context) {
        doValidation([context.recordtype], ['recordtype'], 'POST');
        var rec = record.create({
            type: context.recordtype
        });
        for (var fldName in context)
            if (context.hasOwnProperty(fldName))
                if (fldName !== 'recordtype')
                    rec.setValue(fldName, context[fldName]);
        var recordId = rec.save();
        return String(recordId);
    }
    // Upsert a NetSuite record from request param
    function put(context) {
        doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'PUT');
        var rec = record.load({
            type: context.recordtype,
            id: context.id
        });
        for (var fldName in context)
            if (context.hasOwnProperty(fldName))
                if (fldName !== 'recordtype' && fldName !== 'id')
                    rec.setValue(fldName, context[fldName]);
        rec.save();
        return JSON.stringify(rec);
    }
    return {
        get: _get,
        delete: _delete,
        post: post,
        put: put
    };
})
EN

回答 1

Stack Overflow用户

发布于 2021-05-17 01:01:04

示例代码创建了一个通用的restlet,它允许您对netsuite中的任何记录类型执行通用crud操作。

  • 当使用http get谓词调用此restlet时,它将返回指定的记录(由recordtype和id指定)。
  • 当使用http post谓词调用此restlet时,restlet将创建指定的记录(由recordtype和id指定)。
  • 当使用http put谓词调用此restlet时,restlet将更新指定的记录(由recordtype和id指定)。H29<代码>H110当使用http <代码>D11谓词调用此restlet时,restlet将删除指定的记录(由recordtype,和id指定和id)。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67553469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档