NetSuite UserEventScript:TypeError:在对象标准记录中找不到函数getSubListValue

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

我在NetSuite中创建了一个UserEvent脚本,但是我无法从Items子列表中获取数据。我正在使用getSubListValue方法。有人可以帮我一把吗?我正在发布代码。谢谢!

getSublistText,getSublistField函数

/**
 * @NApiVersion 2.x
 * @NScriptType userEventScript
 * @author Adriano Barbosa
 * @since 2019.2
 */
define(['N/log', 'N/record', 'N/search', 'N/ui/dialog', 'N/ui/serverWidget'], function(log, record, search, dialog, ui) {
    function devolucaoFornecedor(context) {
        var df, total_linhas_itens, codigo_item_linha, qtde_item_linha, peso_item, peso_bruto_liquido;
        df = context.newRecord;
        total_linhas_itens = df.getLineCount({ sublistId: 'item' });
        log.debug({ title: 'total_linhas_itens', details: total_linhas_itens });

        if ( context.type === context.UserEventType.CREATE ) {
            for ( i=0; i<total_linhas_itens; i++ ) {
                // codigo_item_linha = df.getSubListValue({ sublistId: 'item', fieldId: 'item', line: linha_item });
                codigo_item_linha = df.getSubListValue({ sublistId: 'item', fieldId: 'item', line: i });
                log.debug({ title: 'codigo_item_linha', details: codigo_item_linha });

                qtde_item_linha = df.getSubListValue({ subslitId: 'item', field: 'quantity', line: i });
                log.debug({ title: 'qtde_item_linha', details: qtde_item_linha });

                peso_item = record.load({ type: 'inventoryitem', id: codigo_item_linha, isDynamic: true })
                                   .getValue({ fieldId: 'custitem_enl_weight' });
                log.debug({ title: 'peso_item', details: peso_item });

                volumes += qtde_item_linha; 
                peso_bruto_liquido += ( peso_item * qtde_item_linha );
                log.debug({ title: 'volumes', details: volumes });
                log.debug({ title: 'peso_bruto_liquido', details: peso_bruto_liquido });
            }    
            df.setValue({ fieldId: 'custbody_enl_grossweight', value: peso_bruto_liquido });
            df.setValue({ fieldId: 'custbody_enl_netweight', value: peso_bruto_liquido });
            df.setValue({ fieldId: 'custbody_enl_volumesqty', value: volumes });
            df.setValue({ fieldId: 'custbody_enl_volumetype', value: 'PC' });
        }
        return true;        
    }

    return {
        afterSubmit: devolucaoFornecedor
    }
})

TypeError: Can not find function getSubListValue in object standard record
TypeError: Can not find function getSubLisText in object standard record

suitescript2.0
2个回答
2
投票

我认为这只是错字。

getSubListValue(options) - > getSublistValue(options)


0
投票

在朋友Kenji的帮助下,我发布了更新的脚本。我希望它对每个人都有用。谢谢!

/**
 * @NApiVersion 2.x
 * @NScriptType userEventScript
 * @author Adriano Barbosa
 * @since 2019.2
 */
define(['N/log', 'N/record', 'N/search'], function(log, record, search) {
    function devolucaoFornecedor(context) {
        var df, itemCount, id_item_linha, bsc_id_item_linha, qtde_item_linha, peso_item, peso_bl, volumes, 
            peso_total_itens, fornecedor;
        var bodyObject = {}; 
        var itens = [];

        df = context.newRecord;
        itemCount = df.getLineCount({ sublistId: 'item' });
        volumes = 0;
        peso_total_itens = 0;

        for ( linha_item=0; linha_item<itemCount; linha_item++ ) {
            id_item_linha = df.getSublistValue({ sublistId: 'item', fieldId: 'item', line: linha_item });

            bsc_id_item_linha = search.lookupFields({ type: 'inventoryitem', id: id_item_linha, 
                columns: [ 'itemid', 'custitem_enl_weight' ] 
            });

            qtde_item_linha = df.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: linha_item });
            peso_item = bsc_id_item_linha.custitem_enl_weight;
            // peso_bl = (peso_item x qtde_item_linha)
            peso_bl = peso_item * qtde_item_linha;
            // volumes = quantidade de todos os itens da DF
            volumes = qtde_item_linha + volumes;                  
            peso_total_itens = peso_bl + peso_total_itens;

            var itensObj = {};
            itensObj['codigo_item_linha'] = bsc_id_item_linha.itemid;
            itensObj['qtde_item_linha'] = qtde_item_linha;
            itensObj['peso_item'] = peso_item || 0;
            itensObj['peso_bl'] =  peso_bl || 0;
            itensObj['volumes'] = volumes;
            itensObj['peso_total_itens'] = peso_total_itens;
            itens.push(itensObj);
        } 

        if ( context.type === context.UserEventType.CREATE ) {
            bodyObject['total_linhas_itens'] = itemCount;
            bodyObject['peso_geral'] = peso_total_itens;
            bodyObject['volume_geral'] = volumes;
            bodyObject['itens'] = itens;
            df.setValue({ fieldId: 'custbody_enl_grossweight', value: peso_total_itens })
            .setValue({ fieldId: 'custbody_enl_netweight', value: peso_total_itens })
            .setValue({ fieldId: 'custbody_enl_volumesqty', value: volumes })
            .setValue({ fieldId: 'custbody_enl_volumetype', value: 'PC' });
            log.debug({ title: 'Devolução de Fornecedor cadastrada!', details: bodyObject });
            return true;
        } else if ( context.type === context.UserEventType.EDIT ) {
            bodyObject['id_df'] = context.newRecord.id;
            bodyObject['num_df'] = df.getValue({ fieldId: 'tranid' });
            bsc_fornecedor_id_df = search.create({ type: "vendorreturnauthorization",
                filters: [
                   [ "type", "anyof" , "VendAuth" ], "AND", 
                   [ "internalid", "anyof" , bodyObject['id_df'] ], "AND", 
                   ["mainline","is","T"]
                ], 
                columns: [
                   search.createColumn({ name: "formulatext", formula: "{entity}", label: "fornecedor" })
                ]
             }).run().each(function(result){
                 fornecedor = result.getValue({ name: 'formulatext' });
                 log.debug({ title: 'fornecedor', details: fornecedor });
                 return false;
             });
            bodyObject['fornecedor'] = fornecedor || 'Vide num_df';
            bodyObject['total_linhas_itens'] = itemCount;
            bodyObject['peso_geral'] = peso_total_itens;
            bodyObject['volume_geral'] = volumes;
            bodyObject['itens'] = itens;
            df.setValue({ fieldId: 'custbody_enl_grossweight', value: peso_total_itens })
            .setValue({ fieldId: 'custbody_enl_netweight', value: peso_total_itens })
            .setValue({ fieldId: 'custbody_enl_volumesqty', value: volumes })
            .setValue({ fieldId: 'custbody_enl_volumetype', value: 'PC' });
            log.debug({ title: 'Devolução de Fornecedor Modificada', details: bodyObject });
            return true;
        }
        return true;        
    }
    return { beforeSubmit: devolucaoFornecedor }
})
© www.soinside.com 2019 - 2024. All rights reserved.