是否存在用于从NetSuite发送事务的json的解决方案?

问题描述 投票:0回答:1

任何人在与API进行通信方面是否有经验,基本上,每次创建新的商品实现时,我都必须发送商品实现详细信息。

因此,我目前使用的是保存的搜索,但我错过了实时时间。想法是每次启动商品履行时发送一个Json文件。

我没有Suitescript的经验,但是我已经准备好学习。我试图适应的基础以下:

    /*
 * @description send Item Fulfillments data from NetSuite
 *
 * @appliedtorecord itemfulfillment
 */

function afterSubmit(type) {
    try {
        _runAfterSubmit(type, false, null);
    } catch (ex) {
        nlapiLogExecution('error', 'itemfulfillment Outbound', 'Error executing afterSubmit(): ' + ex.toString());
    }
}

function _getRequestHeaders() {
    return {
        'Authorization': 'Basic xxXXXxxXXxXxxxxXXX'
    };
}

function _getURL() {
    var host = _getURLHost();
    var envType = _getURLEnvironment();
    return "https://apilink";
}

function _getURLHost() {
    return "urlHost";
}

function _getURLEnvironment() {
    var noSubNumber = '1234567';
    var sandboxAccountDev = '123456_SB2';

    switch (nlapiGetContext().getCompany()) {
        case noSubNumber:
            var returnVal = 'development/1.0';
            if (nlapiGetContext().getEnvironment() == 'PRODUCTION')
                returnVal = 'Prod/1.0-2';
            return returnVal;
            break;

        case sandboxAccountDev:
            return 'development/1.0';
            break;
    }
}

function _runAfterSubmit(type) {
    var recordId = nlapiGetRecordId();
    var recordType = nlapiGetRecordType();
    var record = null;

    try {
        record = nlapiLoadRecord(recordType, recordId);
    } catch (ex) {
        nlapiLogExecution('emergency', 'itemfulfillment Outbound', 'Error loading record type ' + recordType + ' with ID ' + recordId + ex.toString());
        return;
    }

    try {
        _sendToOutbound(record);
    } catch (ex) {
        nlapiLogExecution('error', 'itemfulfillment Outbound', 'Error sending data for record type ' + recordType + ' with ID: ' + ex.toString());
    }
}  

function _sendToOutbound(record) {
  /*
    var fieldNameSentToOutbound = 'custbody_itemfulfillment_sent_to_Outbound';
    var fieldNameSentToOutboundFailCount = 'custbody_itemfulfillment_sent_to_Outbound_fail_count';
    */
    var recordType = record.getRecordType();
    var recordId = record.getId();
    nlapiLogExecution('audit', 'Invoice Record ID: ' + recordId);

  /*
    try {
        nlapiSubmitField(recordType, recordId, fieldNameSentToOutbound, 'F');
    } catch (ex) {
        nlapiLogExecution('emergency', 'itemfulfillment Outbound', 'Error marking record type ' + recordType + ' with ID ' + recordId + ' as sent not sent to Outbound: ' + ex.toString());
        return;
    }
    */

    var errorPrefix = 'Error sending itemfulfillment data to Outbound (ID: ' + recordId + '): ';
    var url = _getURL();
    var requestHeaders = _getRequestHeaders();



    try {
        var payload = JSON.stringify(record);

        var response = nlapiRequestURL(url, payload, requestHeaders);

        nlapiLogExecution('debug', 'response recordId:response Code ', recordId + " : " + response.getCode());
        var httpResponseCode = response.getCode();
        if (httpResponseCode >= 300) {
            var exMessage = response.getCode();

            throw exMessage;
            return;
        }


    } catch (exceptionSendToOutbound) {


        nlapiLogExecution('error', 'itemfulfillment Outbound', 'Id ' + recordId + ': ' + errorPrefix + exceptionSendToOutbound.toString());    
    }
}

谢谢

netsuite
1个回答
0
投票

[如果只是阅读和发布,则不需要nlapiLoadRecord,只需阅读记录。提交后,类型也应为“创建”。

© www.soinside.com 2019 - 2024. All rights reserved.