You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite客户端脚本:日记账分录自动填充上一行类别与部门

Hey Mark, great question! I’ve tackled this exact NetSuite scenario before, so let me break down how to build this client-side automation step by step.

How to Auto-Populate Class/Department from Previous Journal Entry Line

The key here is using a SuiteScript 2.x Client Script tied to the Journal Entry record, which listens for changes to the Account field in the line sublist and pulls values from the prior line.

Step 1: Write the Client Script

This script will trigger whenever you tab out of the Account field in a new journal line, check the previous line’s Class and Department values, and auto-fill them into the current line.

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/currentRecord'], function(currentRecord) {

    function fieldChanged(context) {
        const rec = context.currentRecord;
        const sublist = context.sublistId;
        const field = context.fieldId;
        const currentLineNum = context.line;

        // Only run logic for the journal entry line sublist and Account field
        if (sublist === 'line' && field === 'account') {
            // Skip the first line (no prior line to copy from)
            if (currentLineNum <= 0) return;

            // Grab values from the immediately preceding line
            const prevLineNum = currentLineNum - 1;
            const prevClass = rec.getCurrentSublistValue({
                sublistId: 'line',
                fieldId: 'class',
                line: prevLineNum
            });
            const prevDept = rec.getCurrentSublistValue({
                sublistId: 'line',
                fieldId: 'department',
                line: prevLineNum
            });

            // Auto-fill current line if prior line had values
            if (prevClass) {
                rec.setCurrentSublistValue({
                    sublistId: 'line',
                    fieldId: 'class',
                    value: prevClass
                });
            }
            if (prevDept) {
                rec.setCurrentSublistValue({
                    sublistId: 'line',
                    fieldId: 'department',
                    value: prevDept
                });
            }
        }
    }

    return {
        fieldChanged: fieldChanged
    };
});

Step 2: Deploy the Script

  1. In NetSuite, go to Customization > Scripting > Scripts > New
  2. Select Client Script as the script type, paste the code above, and save it
  3. Create a deployment for the script:
    • Set Applies To to Journal Entry
    • Set Status to Released
    • Assign appropriate roles (e.g., your finance team roles) that need this functionality

How It Works

  • When you add your first line with Class=AA and Department=BB, then click Add to create a second line
  • Type an Account in the second line’s Account field and press Tab
  • The script detects the Account field change, grabs AA/BB from line 0, and auto-fills them into line 1’s Class and Department fields
  • If the prior line has empty Class/Department values, it won’t overwrite any input you might want to add manually

内容的提问来源于stack exchange,提问作者Mark Wagner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:33:21