【问题标题】:How to set a sublist field value from a form field on edit如何在编辑时从表单字段设置子列表字段值
【发布时间】:2019-06-07 18:59:04
【问题描述】:

我有一个当前正在运行的客户端脚本,它从案例记录的“项目”字段中设置时间跟踪子列表行的服务项目。这发生在 lineInit 上,并且在我添加新行时起作用。 我遇到的问题是我希望它在第一行工作。当记录加载时,有一行已经填充了一些数据,但没有填写服务项目。

如果有人能指出我正确的方向,我将不胜感激。这可以在 pageInit 或 fieldChanged 上工作 - 比如在我更新另一个行字段后更新服务项目?

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([],

function() {

    /**
     * Function to be executed when field is slaved.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.sublistId - Sublist name
     * @param {string} scriptContext.fieldId - Field name
     *
     * @since 2015.2
     */


    function lineInit(scriptContext) {
        if (scriptContext.sublistId !== 'timeitem'){
            console.log('test3');
            return;
        }
        /* {N/currentRecord.CurrentRecord} */
        var rec = scriptContext.currentRecord;
        /* {string} The Service Item in the Body, if any */

        var bodyItem = rec.getValue({fieldId: 'item'});

        /* {string} The class that has been set at the line level, if any */
        var lineServiceItem = rec.getCurrentSublistValue({
            sublistId: 'timeitem',
            fieldId: 'item'
        });

        /* IF there IS a value at the body level, and there is NOT a value at the line */
        if (bodyItem && !lineServiceItem) {
            console.log('test4');
            /* Set the line value to the body value */
            rec.setCurrentSublistValue({
                sublistId: 'timeitem',
                fieldId: 'item',
                value: bodyItem
            });
        }

    }



    return {

        lineInit: lineInit
    };

});

【问题讨论】:

  • 我也尝试过 postSourcing,但它不起作用。我会考虑根据对另一个行级别字段(如持续时间)的编辑在行级别更新服务项目。
  • 您想知道这是否可以通过 pageInit 工作。你试过了吗?这似乎是您最好的选择,因为第一行已经存在。

标签: netsuite suitescript suitescript2.0


【解决方案1】:

必须在 pageInit 期间填充第一行(或编辑模式下的当前行)。

function setLineItem(context, isPageInit) {
    if (isPageInit || (context.sublistId === 'timeitem')) {            
        // set value            
    }
}

function pageInit(context) {
    setLineItem(context, true);
}

function lineInit(context) {
    setLineItem(context);
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多