zoukankan      html  css  js  c++  java
  • netsuite 库存同步机制

    应用调用:
    nlapiServerCall('/app/accounting/transactions/inventory/validateInventoryNumbers.nl', 'getValidationScript', [params], eval);

    实现过程:---------------------   
    * @param url URL of request handler    
    * @param methodName method name on remote object to call    
    * @param methodParams an array of parameters to the method    
    * @param asyncCallback a callback if this is to be an async request. Callback signature should be: callback(result, error)    
    */    
    function nlapiServerCall(url, methodName, methodParams, asyncCallback)    
    {    
    return nsServerCall(url, methodName, methodParams, asyncCallback);    
    }    
        
    function nlapiLocalCall(func, timeoutinmillis)    
    {    
    nsapiAssertTrue(timeoutinmillis != null && !isNaN(parseInt(timeoutinmillis)), 'SSS_INVALID_ARGUMENT', 'timeoutinmillis: '+timeoutinmillis)    
    var obj = new Object()    
    obj.trigger = nsapiQueryScript("trigger")    
    obj.scriptid = nsapiQueryScript("scriptid")    
    if ( timeoutinmillis == -1 )    
    return nsapiCallScript(obj.trigger, obj.scriptid, func)    
    return setTimeout( function() { nsapiCallScript(obj.trigger, obj.scriptid, func); }, timeoutinmillis );    
    }    
    ----------------------------------------
    /**
    * @param url URL of request handler
    * @param methodName method name on remote object to call
    * @param methodParams an array of parameters to the method
    * @param asyncCallback a callback if this is to be an async request. Callback signature should be: callback(result, error)
    */
    function nsServerCall(url, methodName, methodParams, asyncCallback)
    {
    var client = new NLJsonRpcClient(url);
    return client.sendRequest(methodName, methodParams, asyncCallback);
    }

    NLJsonRpcClient = function (serverURL)
    {
    if (serverURL.indexOf("?") > 0)
    serverURL = serverURL + "&jrpc=T";
    else
    serverURL = serverURL + "?jrpc=T";
    this.serverURL = serverURL;
    this.responseCallbackMap = {};
    };
    NLJsonRpcClient.requestId = 0;
    NLJsonRpcClient.prototype =
    {
    sendRequest : function (methodName, args, callback)
    {
    var jsonRpcReq = {
    id : NLJsonRpcClient.requestId++,
    method : "remoteObject." + methodName,
    params : args || []
    };
    if (callback != null)
    this.responseCallbackMap[jsonRpcReq.id] = callback;
    var request = new NLXMLHttpRequest();
    if (callback != null)
    request.setResponseHandler(this.handleResponseAsync.bindAsEventListener(this));
    var response = request.requestURL(this.serverURL, toJSON(jsonRpcReq), null, callback != null ? true : false);
    if (callback == null)
    {
    var jsonRpcResp = this.getJsonRpcResponse(response);
    if (jsonRpcResp.error)
    throw new NLXMLResponseError(jsonRpcResp.error.code, jsonRpcResp.error.trace, jsonRpcResp.error.msg);
    response = jsonRpcResp.result;
    }
    return response;
    },

    getJsonRpcResponse : function (nlXMLResponseObj)
    {
    var jsonRpcResp = nlXMLResponseObj.getBody();
    if (jsonRpcResp != null)
    jsonRpcResp = jsonRpcResp.replace(/^\s*<!--[\s\S]*?-->\s*$/gm, '');
    eval("jsonRpcResp = " + jsonRpcResp + ";");
    return jsonRpcResp;
    },

    handleResponseAsync : function (nlXMLResponseObj)
    {
    var jsonRpcResp = this.getJsonRpcResponse(nlXMLResponseObj);
    var callback = this.responseCallbackMap[jsonRpcResp.id];
    this.responseCallbackMap[jsonRpcResp.id] = null;
    callback(jsonRpcResp.result, jsonRpcResp.error);
    }
    }

    function toJSON(o)
    {
    if (o == null)
    return "null";
    else if(o.constructor == String || o.constructor.name == "String")
    return escapeJSONString(o);
    else if(o.constructor == Number || o.constructor.name == "Number")
    return o.toString();
    else if(o.constructor == Boolean || o.constructor.name == "Boolean")
    return o.toString();
    else if(o.constructor == Date || o.constructor.name == "Date")
    return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}';
    else if((o.constructor == Array || o.constructor.name == "Array"))
    {
    var v = [];
    for (var i = 0; i < o.length; i++) v.push(toJSON(o[i]));
    return "[" + v.join(", ") + "]";
    }
    else
    {
    var v = [];
    for(attr in o)
    {
    if(o[attr] == null) v.push("\"" + attr + "\": null");
    else if(typeof o[attr] == "function"); /* skip */
    else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr]));
    }
    return "{" + v.join(", ") + "}";
    }
    }

    纠正错误,欢迎探讨:
    打开微信-发现-扫一扫
  • 相关阅读:
    转载:[Oracle]杀死正在执行的sql语句
    转载:记录一次MySQL两千万数据的大表优化解决过程
    转载:logback日志详解
    转载:MySQL千万级大表优化攻略
    使用dbUnit的 IDataSet 因乱序造成assert失败而采取的措施
    解锁用户scott并授权
    两表连接各种Join图示,SQL及查询结果
    一句Delete..In.. 删除语句的优化
    大数据技术之_08_Hive学习_02_DDL数据定义(创建/查询/修改/删除数据库+创建表+分区表+修改表+删除表)+DML数据操作(数据导入+数据导出+清除表中数据)
    大数据技术之_08_Hive学习_01_Hive入门+Hive安装、配置和使用+Hive数据类型
  • 原文地址:https://www.cnblogs.com/backuper/p/1552463.html
Copyright © 2011-2022 走看看